Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
skirpichev opened this issue Oct 26, 2023 · 2 comments
Closed

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

skirpichev opened this issue Oct 26, 2023 · 2 comments
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@skirpichev
Copy link
Member

skirpichev commented Oct 26, 2023

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

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)
@skirpichev skirpichev added the type-bug An unexpected behavior, bug, or error label Oct 26, 2023
@iritkatriel iritkatriel added the tests Tests in the Lib/test dir label Nov 24, 2023
@gaogaotiantian
Copy link
Member

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

@skirpichev
Copy link
Member Author

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
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants