Commit Graph

6 Commits

Author SHA1 Message Date
Serhiy Storchaka 190331ed28
[3.10] Add more details in test_unittest (GH-99626). (GH-99692)
(cherry picked from commit 653e563d80)
2022-11-22 17:13:37 +02:00
Miss Islington (bot) 9b070d361d
gh-96021: Explicitly tear down the IsolatedAsyncioTestCase loop in tests (GH-96135) (GH-96235)
Tests for IsolatedAsyncioTestCase.debug() rely on the runner be closed
in __del__. It makes tests depending on the GC an unreliable on other
implementations. It is better to tear down the loop explicitly even if
currently there is no a public API for this.
(cherry picked from commit 4de06e3cc0)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2022-08-28 08:35:39 +03:00
Łukasz Langa 44396aaba9
[3.10] bpo-45238: Fix unittest.IsolatedAsyncioTestCase.debug() (GH-28449) (GH-28521)
It runs now asynchronous methods and callbacks.

If it fails, doCleanups() can be called for cleaning up.
(cherry picked from commit ecb6922ff2)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-09-22 18:42:15 +02:00
Miss Islington (bot) 8516ca500e
bpo-44911: Fixed IsolatedAsyncioTestCase from throwing an exception on leaked tasks (GH-27765)
(cherry picked from commit 2cb1a6806c)

Co-authored-by: Bar Harel <bar.harel@biocatch.com>
2021-08-16 02:54:58 -07:00
Lisa Roach 8374d2ee15
bpo-39101: Fixes BaseException hang in IsolatedAsyncioTestCase. (GH-22654) 2020-10-26 09:28:17 -07:00
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