Łukasz Langa <luk...@langa.pl> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue44852>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to