|
85 | 85 | "skip_unless_symlink", "requires_gzip", "requires_bz2", "requires_lzma", |
86 | 86 | "bigmemtest", "bigaddrspacetest", "cpython_only", "get_attribute", |
87 | 87 | "requires_IEEE_754", "skip_unless_xattr", "requires_zlib", |
88 | | - "anticipate_failure", |
| 88 | + "anticipate_failure", "load_package_tests", |
89 | 89 | # sys |
90 | 90 | "is_jython", "check_impl_detail", |
91 | 91 | # network |
@@ -188,6 +188,25 @@ def anticipate_failure(condition): |
188 | 188 | return unittest.expectedFailure |
189 | 189 | return lambda f: f |
190 | 190 |
|
| 191 | +def load_package_tests(pkg_dir, loader, standard_tests, pattern): |
| 192 | + """Generic load_tests implementation for simple test packages. |
| 193 | +
|
| 194 | + Most packages can implement load_tests using this function as follows: |
| 195 | +
|
| 196 | + def load_tests(*args): |
| 197 | + return load_package_tests(os.path.dirname(__file__), *args) |
| 198 | + """ |
| 199 | + if pattern is None: |
| 200 | + pattern = "test*" |
| 201 | + top_dir = os.path.dirname( # Lib |
| 202 | + os.path.dirname( # test |
| 203 | + os.path.dirname(__file__))) # support |
| 204 | + package_tests = loader.discover(start_dir=pkg_dir, |
| 205 | + top_level_dir=top_dir, |
| 206 | + pattern=pattern) |
| 207 | + standard_tests.addTests(package_tests) |
| 208 | + return standard_tests |
| 209 | + |
191 | 210 |
|
192 | 211 | def import_fresh_module(name, fresh=(), blocked=(), deprecated=False): |
193 | 212 | """Import and return a module, deliberately bypassing sys.modules. |
|
0 commit comments