Author lukasz.langa
Recipients lukasz.langa
Date 2021-08-06.16:57:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1628269070.66.0.586403682706.issue44852@roundup.psfhosted.org>
In-reply-to
Content
For example, all that's needed to silence the 220 new warnings in all asyncio tests, is adding this in Lib/test/test_asyncio/__init__.py:

```
def setUpModule():
    support.ignore_deprecations_from("asyncio.base_events", like=r".*loop argument.*")
    support.ignore_deprecations_from("asyncio.unix_events", like=r".*loop argument.*")
    support.ignore_deprecations_from("asyncio.futures", like=r".*loop argument.*")
    support.ignore_deprecations_from("asyncio.runners", like=r".*loop argument.*")
    support.ignore_deprecations_from("asyncio.subprocess", like=r".*loop argument.*")
    support.ignore_deprecations_from("asyncio.tasks", like=r".*loop argument.*")
    support.ignore_deprecations_from("test.test_asyncio.test_queues", like=r".*loop argument.*")
    support.ignore_deprecations_from("test.test_asyncio.test_tasks", like=r".*loop argument.*")

def tearDownModule():
    support.clear_ignored_deprecations()
```

Since the `__init__.py` file in question isn't a module that runs tests itself but only a package gathering many sub-modules, we need some boilerplate like:

```
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):
        try:
            setUpModule()
            super().run(result, debug=debug)
        finally:
            tearDownModule()
```

With that, all of asyncio tests silence unnecessary deprecation warnings. Additionally, testing for warnings with `warnings_helper.check_warnings()` or `assertWarns` still works just fine as those facilities temporarily disable filtering.
History
Date User Action Args
2021-08-06 16:57:50lukasz.langasetrecipients: + lukasz.langa
2021-08-06 16:57:50lukasz.langasetmessageid: <1628269070.66.0.586403682706.issue44852@roundup.psfhosted.org>
2021-08-06 16:57:50lukasz.langalinkissue44852 messages
2021-08-06 16:57:50lukasz.langacreate