Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Unittests with doctests cannot be loaded in -OO mode #115341

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Bug report

For example:

$ ./pythonx -OO -m test -vuall test_code
...
0:00:00 load avg: 1.64 [1/1] test_code
Failed to call load_tests:
Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/unittest/loader.py", line 113, in loadTestsFromModule
    return load_tests(self, tests, pattern)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/test/test_code.py", line 880, in load_tests
    tests.addTest(doctest.DocTestSuite())
                  ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/serhiy/py/cpython/Lib/doctest.py", line 2452, in DocTestSuite
    suite.addTest(SkipDocTestCase(module))
                  ~~~~~~~~~~~~~~~^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/doctest.py", line 2386, in __init__
    DocTestCase.__init__(self, None)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/doctest.py", line 2228, in __init__
    self._dt_globs = test.globs.copy()
                     ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'globs'

test test_code crashed -- Traceback (most recent call last):
  File "/home/serhiy/py/cpython/Lib/test/libregrtest/single.py", line 178, in _runtest_env_changed_exc
    _load_run_test(result, runtests)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/test/libregrtest/single.py", line 135, in _load_run_test
    regrtest_runner(result, test_func, runtests)
    ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/test/libregrtest/single.py", line 88, in regrtest_runner
    test_result = test_func()
                  ~~~~~~~~~^^
  File "/home/serhiy/py/cpython/Lib/test/libregrtest/single.py", line 132, in test_func
    return run_unittest(test_mod)
           ~~~~~~~~~~~~^^^^^^^^^^
  File "/home/serhiy/py/cpython/Lib/test/libregrtest/single.py", line 35, in run_unittest
    raise Exception("errors while loading tests")
Exception: errors while loading tests

test_code failed (uncaught exception)

== Tests result: FAILURE ==
...

It seems that the regression was caused by 7ba7eae (GH-31932, bpo-2604).

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixes3.12only security fixes3.13bugs and security fixestestsTests 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