Issue 19013: unittest's own test suite is not CLI-friendly (original) (raw)

When trying to use a standard load_tests() inside a main.py, I get the following kind of errors:

====================================================================== ERROR: test_suite (unittest.loader.ModuleImportFailure)

Traceback (most recent call last): File "/home/antoine/cpython/default/Lib/unittest/case.py", line 56, in testPartExecutor yield File "/home/antoine/cpython/default/Lib/unittest/case.py", line 496, in run testMethod() File "/home/antoine/cpython/default/Lib/unittest/loader.py", line 32, in testFailure raise exception ImportError: Failed to import test module: test_suite Traceback (most recent call last): File "/home/antoine/cpython/default/Lib/unittest/loader.py", line 272, in _find_tests module = self._get_module_from_name(name) File "/home/antoine/cpython/default/Lib/unittest/loader.py", line 250, in _get_module_from_name import(name) File "/home/antoine/cpython/default/Lib/unittest/test/test_suite.py", line 6, in from .support import LoggingResult, TestEquality SystemError: Parent module '' not loaded, cannot perform relative import

... which means that loader.discover() doesn't try to import the test modules as part of their parent package, but as if they were standalone modules :-(