|
1 | 1 | import os
|
2 |
| -from test.support import load_package_tests, import_module |
| 2 | +from test import support |
| 3 | +import unittest |
3 | 4 |
|
4 | 5 | # Skip tests if we don't have concurrent.futures.
|
5 |
| -import_module('concurrent.futures') |
| 6 | +support.import_module('concurrent.futures') |
| 7 | +module_deprecation_tokens = set() |
6 | 8 |
|
7 |
| -def load_tests(*args): |
8 |
| - return load_package_tests(os.path.dirname(__file__), *args) |
| 9 | + |
| 10 | +def load_tests(loader, _, pattern): |
| 11 | + pkg_dir = os.path.dirname(__file__) |
| 12 | + suite = AsyncioTestSuite() |
| 13 | + return support.load_package_tests(pkg_dir, loader, suite, pattern) |
| 14 | + |
| 15 | + |
| 16 | +class AsyncioTestSuite(unittest.TestSuite): |
| 17 | + """A custom test suite that also runs setup/teardown for the whole package. |
| 18 | +
|
| 19 | + Normally unittest only runs setUpModule() and tearDownModule() within each |
| 20 | + test module part of the test suite. Copying those functions to each file |
| 21 | + would be tedious, let's run this once and for all. |
| 22 | + """ |
| 23 | + def run(self, result, debug=False): |
| 24 | + try: |
| 25 | + setUpModule() |
| 26 | + super().run(result, debug=debug) |
| 27 | + finally: |
| 28 | + tearDownModule() |
| 29 | + |
| 30 | + |
| 31 | +def setUpModule(): |
| 32 | + ignore = support.ignore_deprecations_from |
| 33 | + module_deprecation_tokens.update(( |
| 34 | + ignore("asyncio.base_events", like=r".*loop argument.*"), |
| 35 | + ignore("asyncio.unix_events", like=r".*loop argument.*"), |
| 36 | + ignore("asyncio.futures", like=r".*loop argument.*"), |
| 37 | + ignore("asyncio.runners", like=r".*loop argument.*"), |
| 38 | + ignore("asyncio.subprocess", like=r".*loop argument.*"), |
| 39 | + ignore("asyncio.tasks", like=r".*loop argument.*"), |
| 40 | + ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"), |
| 41 | + ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"), |
| 42 | + )) |
| 43 | + |
| 44 | + |
| 45 | +def tearDownModule(): |
| 46 | + support.clear_ignored_deprecations(*module_deprecation_tokens) |
0 commit comments