cpython/Lib/unittest
Andrew Svetlov 4dd3e3f9bb bpo-32972: Async test case (GH-13386)
Add explicit `asyncSetUp` and `asyncTearDown` methods.
The rest is the same as for #13228

`AsyncTestCase` create a loop instance for every test for the sake of test isolation.
Sometimes a loop shared between all tests can speed up tests execution time a lot but it requires control of closed resources after every test finish. Basically, it requires nested supervisors support that was discussed with @1st1 many times. Sorry, asyncio supervisors have no chance to land on Python 3.8.

The PR intentionally does not provide API for changing the used event loop or getting the test loop: use `asyncio.set_event_loop_policy()` and `asyncio.get_event_loop()` instead.

The PR adds four overridable methods to base `unittest.TestCase` class:
```
    def _callSetUp(self):
        self.setUp()

    def _callTestMethod(self, method):
        method()

    def _callTearDown(self):
        self.tearDown()

    def _callCleanup(self, function, /, *args, **kwargs):
        function(*args, **kwargs)
```
It allows using asyncio facilities with minimal influence on the unittest code.

The last but not least: the PR respects contextvars. The context variable installed by `asyncSetUp` is available on test, `tearDown` and a coroutine scheduled by `addCleanup`.


https://bugs.python.org/issue32972
2019-05-29 02:33:59 -07:00
..
test bpo-32972: Async test case (GH-13386) 2019-05-29 02:33:59 -07:00
__init__.py bpo-32972: Async test case (GH-13386) 2019-05-29 02:33:59 -07:00
__main__.py bpo-29919: Remove unused imports found by pyflakes (#137) 2017-03-27 16:05:26 +02:00
async_case.py bpo-32972: Async test case (GH-13386) 2019-05-29 02:33:59 -07:00
case.py bpo-32972: Async test case (GH-13386) 2019-05-29 02:33:59 -07:00
loader.py bpo-35767: Fix unittest.loader to allow partials as test_functions (#11600) 2019-01-23 21:57:25 +01:00
main.py bpo-32071: Add unittest -k option (#4496) 2017-11-25 16:23:52 +01:00
mock.py bpo-37075: Fix string concatenation in assert_has_awaits error message (GH-13616) 2019-05-29 00:02:25 -07:00
result.py Issue #27076: Doc, comment and tests spelling fixes 2016-05-26 05:35:26 +00:00
runner.py bpo-35513, unittest: TextTestRunner uses time.perf_counter() (GH-11180) 2018-12-17 11:30:34 +01:00
signals.py Closes issue 15505. unittest.installHandler and non-callable signal handlers. 2013-01-29 23:07:57 +00:00
suite.py bpo-24412: Adds cleanUps for setUpClass and setUpModule. (GH-9190) 2018-11-08 18:34:33 -08:00
util.py bpo-32360: unittest.util: Use Counter instead of custom count function (GH-4994) 2018-01-24 16:49:58 +09:00