Skip to content

./python -m test --coverage test_doctest is broken #111355

Closed

Description

@skirpichev

I have (current main):

$ ./python -m test --coverage test_doctest
Using random seed: 3179682031
0:00:00 load avg: 0.55 Run 1 test sequentially
0:00:00 load avg: 0.55 [1/1] test_doctest
test_doctest passed in 35.7 sec

== Tests result: SUCCESS ==

1 test OK.

Total duration: 35.7 sec
Total tests: run=63
Total test files: run=1/1
Result: SUCCESS
Not printing coverage data for '/tmp/tmpfuj65rqc/doctest_testpkg/__init__.py': [Errno 2] No such file or directory: '/tmp/tmpfuj65rqc/doctest_testpkg/__init__.py'
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/sk/src/cpython/Lib/test/__main__.py", line 2, in <module>
    main(_add_python_opts=True)
  File "/home/sk/src/cpython/Lib/test/libregrtest/main.py", line 665, in main
    Regrtest(ns, _add_python_opts=_add_python_opts).main(tests=tests)
  File "/home/sk/src/cpython/Lib/test/libregrtest/main.py", line 657, in main
    exitcode = self.run_tests(selected, tests)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sk/src/cpython/Lib/test/libregrtest/main.py", line 494, in run_tests
    return self._run_tests(selected, tests)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/sk/src/cpython/Lib/test/libregrtest/main.py", line 474, in _run_tests
    self.finalize_tests(tracer)
  File "/home/sk/src/cpython/Lib/test/libregrtest/main.py", line 374, in finalize_tests
    results.write_results(show_missing=True, summary=True,
  File "/home/sk/src/cpython/Lib/trace.py", line 273, in write_results
    with open(filename, 'rb') as fp:
         ^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmpfuj65rqc/doctest_testpkg/__init__.py'

After removing problem doctest

Details
diff --git a/Lib/test/test_doctest.py b/Lib/test/test_doctest.py
index 6a903ed041..55c413d183 100644
--- a/Lib/test/test_doctest.py
+++ b/Lib/test/test_doctest.py
@@ -2851,31 +2851,6 @@ def test_lineendings(): r"""
 at least one of the line endings will raise a ValueError for inconsistent
 whitespace if doctest does not correctly do the newline conversion.
 
-    >>> from test.support import os_helper
-    >>> import shutil
-    >>> dn = tempfile.mkdtemp()
-    >>> pkg = os.path.join(dn, "doctest_testpkg")
-    >>> os.mkdir(pkg)
-    >>> os_helper.create_empty_file(os.path.join(pkg, "__init__.py"))
-    >>> fn = os.path.join(pkg, "doctest_testfile.txt")
-    >>> with open(fn, 'wb') as f:
-    ...     f.write(
-    ...         b'Test:\r\n\r\n'
-    ...         b'  >>> x = 1 + 1\r\n\r\n'
-    ...         b'Done.\r\n'
-    ...         b'Test:\n\n'
-    ...         b'  >>> x = 1 + 1\n\n'
-    ...         b'Done.\n'
-    ...         b'Test:\r\r'
-    ...         b'  >>> x = 1 + 1\r\r'
-    ...         b'Done.\r'
-    ...     )
-    95
-    >>> with test_hook(dn):
-    ...     doctest.testfile("doctest_testfile.txt", package="doctest_testpkg", verbose=False)
-    TestResults(failed=0, attempted=3)
-    >>> shutil.rmtree(dn)
-
 """
 
 def test_testmod(): r"""

I got some coverage for the module:

$ ./python -m test --coverage test_doctest | grep doctest
0:00:00 load avg: 1.11 [1/1] test_doctest
test_doctest passed in 37.7 sec
 1099    69%   doctest   (/home/sk/src/cpython/Lib/doctest.py)
    5    80%   test.doctest_aliases   (/home/sk/src/cpython/Lib/test/doctest_aliases.py)
   17    82%   test.doctest_lineno   (/home/sk/src/cpython/Lib/test/doctest_lineno.py)
   13   100%   test.sample_doctest   (/home/sk/src/cpython/Lib/test/sample_doctest.py)
    3    66%   test.sample_doctest_no_docstrings   (/home/sk/src/cpython/Lib/test/sample_doctest_no_docstrings.py)
    5    80%   test.sample_doctest_no_doctests   (/home/sk/src/cpython/Lib/test/sample_doctest_no_doctests.py)
  208    78%   test.test_doctest   (/home/sk/src/cpython/Lib/test/test_doctest.py)

Activity

  1. gaogaotiantian commented on Feb 4, 2024

    @gaogaotiantian
    Member

    I think this is fixed so maybe we can close the issue now?

  2. skirpichev commented on Feb 4, 2024

    @skirpichev
    MemberAuthor

    Yeah, I can't reproduce this in the current main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions