summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio/__init__.py
blob: 4a7a868980d88be11d6d1b8e75fb0f7ababb2c02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
from test import support
import unittest

# Skip tests if we don't have concurrent.futures.
support.import_module('concurrent.futures')


def load_tests(loader, _, pattern):
    pkg_dir = os.path.dirname(__file__)
    suite = AsyncioTestSuite()
    return support.load_package_tests(pkg_dir, loader, suite, pattern)


class AsyncioTestSuite(unittest.TestSuite):
    """A custom test suite that also runs setup/teardown for the whole package.

    Normally unittest only runs setUpModule() and tearDownModule() within each
    test module part of the test suite. Copying those functions to each file
    would be tedious, let's run this once and for all.
    """
    def run(self, result, debug=False):
        ignore = support.ignore_deprecations_from
        tokens = {
            ignore("asyncio.base_events", like=r".*loop argument.*"),
            ignore("asyncio.unix_events", like=r".*loop argument.*"),
            ignore("asyncio.futures", like=r".*loop argument.*"),
            ignore("asyncio.runners", like=r".*loop argument.*"),
            ignore("asyncio.subprocess", like=r".*loop argument.*"),
            ignore("asyncio.tasks", like=r".*loop argument.*"),
            ignore("test.test_asyncio.test_events", like=r".*loop argument.*"),
            ignore("test.test_asyncio.test_queues", like=r".*loop argument.*"),
            ignore("test.test_asyncio.test_tasks", like=r".*loop argument.*"),
        }
        try:
            super().run(result, debug=debug)
        finally:
            support.clear_ignored_deprecations(*tokens)