Opened 7 years ago

Last modified 7 years ago

#17404 needs_work enhancement

long time doctests in multi-line code not detected

Reported by: dkrenn Owned by:
Priority: major Milestone: sage-6.5
Component: doctest framework Keywords: doctest, multiline code, long time
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

When having a file long-doctest-bug.py with a function

def f(t):
    """
    TESTS::

        sage: f(2)
        sage: f(3)  # long time
        sage: [f(4),
        ....: ]  # long time
        sage: [f(5),  # long time
        ....: ]
        
    """
    print "sleep", t
    sleep(t)

and doctesting it with sage -t long-doctest-bug.py, the line containing f(4) is tested as well:

Running doctests with ID 2014-11-26-16-34-55-f22cca2c.
Doctesting 1 file.
sage -t long-doctest-bug.py
**********************************************************************
File "long-doctest-bug.py", line 5, in long-doctest-bug.f
Failed example:
    f(2)
Expected nothing
Got:
    sleep 2
**********************************************************************
File "long-doctest-bug.py", line 7, in long-doctest-bug.f
Failed example:
    [f(4),
    ]  # long time
Expected nothing
Got:
    sleep 4
    [None]
**********************************************************************
1 item had failures:
   2 of   3 in long-doctest-bug.f
    [2 tests, 2 failures, 6.01 s]
----------------------------------------------------------------------
sage -t long-doctest-bug.py  # 2 doctests failed
----------------------------------------------------------------------
Total time for all tests: 6.0 seconds
    cpu time: 0.0 seconds
    cumulative wall time: 6.0 seconds

Anyhow, note that it works when # long time is put at the end of the first line, which can look weird.

Change History (2)

comment:1 follow-up: Changed 7 years ago by jdemeyer

  • Milestone changed from sage-6.5 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

Feature, not a bug.

Requiring doctest tags to be on the first line makes them much easier to see.

comment:2 in reply to: ↑ 1 Changed 7 years ago by dkrenn

  • Milestone changed from sage-duplicate/invalid/wontfix to sage-6.5
  • Status changed from needs_review to needs_work
  • Type changed from defect to enhancement

Replying to jdemeyer:

Feature, not a bug.

Ok. It's now an enhancement...

Requiring doctest tags to be on the first line makes them much easier to see.

I'm not happy with this. Comments within one code statement can be confusing. IMHO both should work, i.e., putting "# long time" in the first line as well as in the last line (or even in any line at the end).

This would also support the following: When writing doctests I often start with a one-liner. Then later, when it works, I'll rewrite it to multiple lines. The current behavior means, I have to change where the comment is. The reverse situation also happens: You have a multi-line doctest, but then you change it and suddenly it fits into one line. Thus, you now have to move the "# long time" from somewhere in betweeb to the end of the line.

Note: See TracTickets for help on using tickets.