New GitHub issue #101018 from zware:<br>
<hr>
<pre>
Example:
```python
import unittest
events = []
class Test(unittest.IsolatedAsyncioTestCase):
def test(self):
events.append('started')
self.addCleanup(events.append, 'cleanup')
self.doCleanups()
events.append('end')
unittest.main(exit=False)
assert events == ['started', 'cleanup', 'end'], events
```
The above passes in 3.9 and 3.10, but fails in 3.11 with
```
E
======================================================================
ERROR: test (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/.../cpython/Lib/unittest/async_case.py", line 75, in _callCleanup
self._callMaybeAsync(function, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/.../cpython/Lib/unittest/async_case.py", line 95, in _callMaybeAsync
return self._asyncioTestContext.run(func, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: cannot enter context: <_contextvars.Context object at 0x7fb2f93a9900> is already entered
----------------------------------------------------------------------
Ran 1 test in 0.002s
FAILED (errors=1)
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
AssertionError: ['started', 'end']
```
`git bisect` found the culprit to be gh-91150/GH-31837.
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/101018">View on GitHub</a>
<p>Labels: type-bug, expert-asyncio, stdlib, 3.11, 3.12</p>
<p>Assignee: </p>