[docs] [issue16171] "do nothing" load_tests could be improved
Antoine Pitrou
report at bugs.python.org
Tue Oct 9 10:23:55 CEST 2012
New submission from Antoine Pitrou:
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
----------
assignee: docs at python
components: Documentation
messages: 172460
nosy: docs at python, ezio.melotti, michael.foord, pitrou
priority: low
severity: normal
status: open
title: "do nothing" load_tests could be improved
versions: Python 2.7, Python 3.2, Python 3.3, Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue16171>
_______________________________________
More information about the docs
mailing list