From: Antoine Pitrou Date: Fri, 13 Sep 2013 22:37:18 +0000 (+0200) Subject: Issue #19013: add a __main__ to unittest.test to ease CLI invocation X-Git-Tag: v3.4.0a3~72 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e1ba8df182923c103fd595a1a0c5a8be9b381dbb;p=python Issue #19013: add a __main__ to unittest.test to ease CLI invocation --- diff --git a/Lib/unittest/test/__main__.py b/Lib/unittest/test/__main__.py new file mode 100644 index 0000000000..44d0591e84 --- /dev/null +++ b/Lib/unittest/test/__main__.py @@ -0,0 +1,18 @@ +import os +import unittest + + +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" + # We are inside unittest.test, so the top-level is two notches up + top_level_dir = os.path.dirname(os.path.dirname(this_dir)) + package_tests = loader.discover(start_dir=this_dir, pattern=pattern, + top_level_dir=top_level_dir) + standard_tests.addTests(package_tests) + return standard_tests + + +if __name__ == '__main__': + unittest.main()