Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions alt_pytest_asyncio/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ def __init__(self, *, default_timeout: float) -> None:
def use_default_timeout(self) -> None:
self.set_timeout_seconds(self.timeout)

def debugger_enabled(self) -> bool:
if sys.version_info >= (3, 12):
return sys.monitoring.get_tool(sys.monitoring.DEBUGGER_ID) is not None
else:
# sys.gettrace is not a language feature and not guaranteed to be available
# on all python implementations, so we see if it exists
gettrace = getattr(sys, "gettrace", None)
return gettrace is not None and gettrace() is not None

def set_timeout_seconds(self, timeout: float) -> None:
if self._timeout:
self._timeout.cancel()
Expand All @@ -130,10 +139,7 @@ def timeout_task(task: asyncio.Task[object] | None) -> None:

if task and not task.done():
# If the debugger is active then don't cancel, so that debugging may continue
# sys.gettrace is not a language feature and not guaranteed to be available
# on all python implementations, so we see if it exists
gettrace = getattr(sys, "gettrace", None)
if gettrace is None or gettrace() is None:
if not self.debugger_enabled():
self.cancelled = True
task.cancel()

Expand Down
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ generator fixtures.
Changelog
---------

.. _release-0.9.4:

0.9.4 - TBD
* Make the plugin aware of PEP 669 (`#33 <https://github.com/delfick/alt-pytest-asyncio/pull/33>`_)

.. _release-0.9.3:

0.9.3 - 14 April 2025
Expand Down