Skip to content

Commit 8277ed7

Browse files
committed
fixtures: ensure cm fixtures don't finalize if never started
1 parent 54f97d7 commit 8277ed7

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ generator fixtures.
2121
Changelog
2222
---------
2323

24+
0.5.5 - TBD
25+
* Fix bug where it was possible for an async generator fixture to
26+
be cleaned up even if it was never started.
27+
2428
0.5.4 - 26 January 2021
2529
* Added a ``--default-async-timeout`` option from the CLI. With many thanks
2630
to @andredias.

alt_pytest_asyncio/async_converters.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ def finalizer():
189189
"""Yield again, to finalize."""
190190
__tracebackhide__ = True
191191

192+
nonlocal info
193+
if "ran_once" not in info:
194+
return
195+
192196
info = {"gen_obj": gen_obj, "finalizer": True}
193197

194198
async def async_finalizer():
@@ -242,3 +246,5 @@ def timeout_task(task):
242246
exc_info = sys.exc_info()
243247
e = exc_info[1]
244248
info["e"] = e
249+
finally:
250+
info["ran_once"] = True

0 commit comments

Comments
 (0)