This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: python3 -m doctest test.py tests the stdlib "time" module instead
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8, Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: gvanrossum, stijnvandrongelen
Priority: normal Keywords:

Created on 2021-01-12 10:39 by stijnvandrongelen, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg384913 - (view) Author: Stijn van Drongelen (stijnvandrongelen) Date: 2021-01-12 10:39
I have two files, named time.py and time_.py, with the same contents:

    def foo():
        """Returns 1.

        >>> foo()
        1
        """
        return 1

When I run

    python3 -m doctest -v time_.py

I see the expected behaviour:

    Trying:
        foo()
    Expecting:
        1
    ok
    1 items had no tests:
        time_
    1 items passed all tests:
       1 tests in time_.foo
    1 tests in 2 items.
    1 passed and 0 failed.
    Test passed.

However, when I run

    python3 -m doctest -v time_.py

it seems like doctest is testing the standard library 'time' module, while I expected it to have similar output as seen above:

        30 items had no tests:
        time
        time.asctime
      (... skipped 24 lines for the bug report ...)
        time.time_ns
        time.tzset
    0 tests in 30 items.
    0 passed and 0 failed.
    Test passed.

The same happens when I provide a path with slashes in it.
msg384914 - (view) Author: Stijn van Drongelen (stijnvandrongelen) Date: 2021-01-12 10:48
Reproducible in Python 3.8.7 and 3.9.1.
msg384973 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-12 18:22
Sorry, this is not a bug. The builtin time module takes precedence in this case because the current directory is not put at the front of the module search path (sys.path).

As a workaround you could exportPYTHONPATH=.
msg384974 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2021-01-12 18:22
Whoops, I meant

export PYTHONPATH=.
History
Date User Action Args
2022-04-11 14:59:40adminsetgithub: 87072
2021-01-12 18:22:32gvanrossumsetmessages: + msg384974
2021-01-12 18:22:19gvanrossumsetstatus: open -> closed

nosy: + gvanrossum
messages: + msg384973

resolution: not a bug
stage: resolved
2021-01-12 10:48:34stijnvandrongelensetmessages: + msg384914
versions: + Python 3.8, Python 3.9
2021-01-12 10:39:42stijnvandrongelencreate