diff options
author | Zachary Ware <zachary.ware@gmail.com> | 2014-07-23 17:00:29 (GMT) |
---|---|---|
committer | Zachary Ware <zachary.ware@gmail.com> | 2014-07-23 17:00:29 (GMT) |
commit | f012ba42fe54253378a2784aaf7177aa36be579a (patch) | |
tree | 44f904dd1023616f134f1e8f2cddac0185cd313e /Lib/test/support | |
parent | c4c464911ab6a65a32b8b2162aa4537003efb87b (diff) | |
download | cpython-f012ba42fe54253378a2784aaf7177aa36be579a.zip cpython-f012ba42fe54253378a2784aaf7177aa36be579a.tar.gz cpython-f012ba42fe54253378a2784aaf7177aa36be579a.tar.bz2 |
Issue #22002: Make full use of test discovery in test sub-packages.
Adds `load_package_tests` function to test.support, uses it in test_asyncio,
test_email, test_json, test_tools, test_importlib and all test_importlib
sub-packages to implement test discovery.
Diffstat (limited to 'Lib/test/support')
-rw-r--r-- | Lib/test/support/__init__.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py index 9ec4e7c..f2c1a92 100644 --- a/Lib/test/support/__init__.py +++ b/Lib/test/support/__init__.py @@ -85,7 +85,7 @@ __all__ = [ "skip_unless_symlink", "requires_gzip", "requires_bz2", "requires_lzma", "bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute", "requires_IEEE_754", "skip_unless_xattr", "requires_zlib", - "anticipate_failure", + "anticipate_failure", "load_package_tests", # sys "is_jython", "check_impl_detail", # network @@ -188,6 +188,25 @@ def anticipate_failure(condition): return unittest.expectedFailure return lambda f: f +def load_package_tests(pkg_dir, loader, standard_tests, pattern): + """Generic load_tests implementation for simple test packages. + + Most packages can implement load_tests using this function as follows: + + def load_tests(*args): + return load_package_tests(os.path.dirname(__file__), *args) + """ + if pattern is None: + pattern = "test*" + top_dir = os.path.dirname( # Lib + os.path.dirname( # test + os.path.dirname(__file__))) # support + package_tests = loader.discover(start_dir=pkg_dir, + top_level_dir=top_dir, + pattern=pattern) + standard_tests.addTests(package_tests) + return standard_tests + def import_fresh_module(name, fresh=(), blocked=(), deprecated=False): """Import and return a module, deliberately bypassing sys.modules. |