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: "do nothing" load_tests could be improved
Type: Stage: resolved
Components: Documentation Versions: Python 3.2, Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: pattern=None when following documentation for load_tests and unittest.main()
View: 11218
Assigned To: docs@python Nosy List: docs@python, ezio.melotti, michael.foord, pitrou
Priority: low Keywords:

Created on 2012-10-09 08:23 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg172460 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2012-10-09 08:23
unittest docs suggest the following "load_tests" for a __main__.py:

def load_tests(loader, standard_tests, pattern):
    # top level directory cached on loader instance
    this_dir = os.path.dirname(__file__)
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    standard_tests.addTests(package_tests)
    return standard_tests

This function fails with a weird error message when no pattern is given on the command line. A better alternative would be:

def load_tests(loader, standard_tests, pattern):
    # top level directory cached on loader instance
    this_dir = os.path.dirname(__file__)
    pattern = pattern or "test_*.py"
    package_tests = loader.discover(start_dir=this_dir, pattern=pattern)
    standard_tests.addTests(package_tests)
    return standard_tests
msg172462 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2012-10-09 09:18
Yes the version of load_tests you show is better. However there is an outstanding issue to fix the load_tests protocol to work with pattern=None which is a better fix. (I think this is a bug in load_tests rather than a doc issue really.)

Issue 11218.
History
Date User Action Args
2022-04-11 14:57:37adminsetgithub: 60375
2012-10-09 09:18:46michael.foordsetstatus: open -> closed
superseder: pattern=None when following documentation for load_tests and unittest.main()
messages: + msg172462

resolution: duplicate
stage: resolved
2012-10-09 08:23:55pitroucreate