Skip to content

Commit 7ad0191

Browse files
committed
Backport PEP669 awareness to 0.7.x
1 parent f9438c6 commit 7ad0191

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

README.rst

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

24+
0.7.3 - TBD
25+
* Make the plugin aware of PEP669
26+
2427
0.7.2 - 1 October 2023
2528
* Timeouts don't take affect if the debugger is active
2629

alt_pytest_asyncio/async_converters.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,19 @@ async def async_runner(func, timeout, info, args, kwargs):
231231
else:
232232
current_task = asyncio.Task.current_task()
233233

234+
def debugger_enabled():
235+
if sys.version_info >= (3, 12):
236+
return sys.monitoring.get_tool(sys.monitoring.DEBUGGER_ID) is not None
237+
else:
238+
# sys.gettrace is not a language feature and not guaranteed to be available
239+
# on all python implementations, so we see if it exists
240+
gettrace = getattr(sys, "gettrace", None)
241+
return gettrace is not None and gettrace() is not None
242+
234243
def timeout_task(task):
235244
if not task.done():
236245
# If the debugger is active then don't cancel, so that debugging may continue
237-
# sys.gettrace is not a language feature and notguaranteed to be available
238-
# on all python implementations, so we see if it exists
239-
gettrace = getattr(sys, "gettrace", None)
240-
if gettrace is None or gettrace() is None:
246+
if not debugger_enabled():
241247
info["cancelled"] = True
242248
task.cancel()
243249

0 commit comments

Comments
 (0)