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: unittest's own test suite is not CLI-friendly
Type: enhancement Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, ezio.melotti, michael.foord, pitrou, python-dev
Priority: normal Keywords:

Created on 2013-09-13 19:49 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (6)
msg197634 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-13 19:49
Nothing happens when you try to execute it on the command line:

$ ./python -m unittest.test
/home/antoine/cpython/default/python: No module named unittest.test.__main__; 'unittest.test' is a package and cannot be directly executed
$ ./python -m unittest.test.test_case
$
msg197670 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-09-13 21:54
New changeset 1d08ce952592 by Antoine Pitrou in branch 'default':
Issue #19013: add unittest.main() epilogs to unittest's own test modules
http://hg.python.org/cpython/rev/1d08ce952592

New changeset f81a53580c45 by Antoine Pitrou in branch 'default':
Issue #19013: add unittest.main() epilogs to unittest.mock's own test modules
http://hg.python.org/cpython/rev/f81a53580c45
msg197671 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-13 21:59
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 <module>
    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 :-(
msg197673 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-09-13 22:38
New changeset bbcdcdb06c66 by Antoine Pitrou in branch 'default':
Issue #19013: add a __main__ to unittest.test to ease CLI invocation
http://hg.python.org/cpython/rev/bbcdcdb06c66
msg197674 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-09-13 22:39
New changeset c2b926c0d0c2 by Antoine Pitrou in branch 'default':
Issue #19013: add a __main__ to unittest.test.testmock to ease CLI invocation
http://hg.python.org/cpython/rev/c2b926c0d0c2
msg197675 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-09-13 22:39
Fixed.
History
Date User Action Args
2022-04-11 14:57:50adminsetgithub: 63213
2013-09-13 22:39:44pitrousetstatus: open -> closed
resolution: fixed
messages: + msg197675

stage: needs patch -> resolved
2013-09-13 22:39:21python-devsetmessages: + msg197674
2013-09-13 22:38:02python-devsetmessages: + msg197673
2013-09-13 21:59:01pitrousetmessages: + msg197671
2013-09-13 21:54:07python-devsetnosy: + python-dev
messages: + msg197670
2013-09-13 21:19:54berker.peksagsetnosy: + berker.peksag
2013-09-13 19:49:11pitroucreate