You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
diff --git a/tests/conftest.py b/tests/conftest.py
index 74ff8dbb8de..788cf0a6a9e 100644
--- a/tests/conftest.py+++ b/tests/conftest.py@@ -1,6 +1,7 @@
import os
+import signal
import sys
-from collections.abc import MutableMapping+from collections.abc import Generator, MutableMapping
import psutil
import pytest
@@ -146,3 +147,29 @@ def check_leaked_responses_mocks():
f"`responses` were leaked outside of the test context:\n{leaked_s}"
f"(make sure to use `@responses.activate` or `with responses.mock:`)"
)
+++def _leaked_signals() -> list[str]:+ leaked = []+ for signum in signal.Signals:+ got = signal.getsignal(signum)+ if (+ got is not None+ and not isinstance(got, int)+ and got is not signal.default_int_handler+ # prevent the debugger from interrupting teardown+ and "Pdb.sigint_handler" not in str(got)+ ):+ leaked.append(f"- {signum}: {got}")+ return leaked+++@pytest.fixture(autouse=True)+def check_leaked_signals() -> Generator[None]:+ before = frozenset(_leaked_signals())+ yield+ after = _leaked_signals()++ leaked = [msg for msg in after if msg not in before]+ if leaked:+ raise AssertionError(f"test leaked os signal handlers:\n{'\n'.join(leaked)}")
when applied can result in tests failing
$ pytest tests/sentry/taskworker/test_worker.py::test_child_worker_failure_task
============================= test session starts ==============================
platform darwin -- Python 3.13.1, pytest-8.1.2, pluggy-1.5.0
django: version: 5.1.7
rootdir: /Users/asottile/workspace/sentry
configfile: pyproject.toml
plugins: fail-slow-0.3.0, repeat-0.9.3, time-machine-2.16.0, json-report-1.5.0, metadata-3.1.1, xdist-3.0.2, django-4.9.0, pytest_sentry-0.3.0, anyio-3.7.1, rerunfailures-15.0, cov-4.0.0
collected 1 item
tests/sentry/taskworker/test_worker.py .E [100%]
==================================== ERRORS ====================================
_____________ ERROR at teardown of test_child_worker_failure_task ______________
tests/conftest.py:175: in check_leaked_signals
raise AssertionError(f"test leaked os signal handlers:\n{'\n'.join(leaked)}")
E AssertionError: test leaked os signal handlers:
E - 14: <function child_worker.<locals>.handle_alarm at 0x12d0c65c0>
=========================== short test summary info ============================
ERROR tests/sentry/taskworker/test_worker.py::test_child_worker_failure_task - AssertionError: test leaked os signal handlers:
========================== 1 passed, 1 error in 4.56s ==========================
The text was updated successfully, but these errors were encountered:
There are some tests for `child_worker` that are not in child processes,
and we're currently leaking signal handlers. Use a context manager to
add/cancel the signal handler.
Fixes#88742
There are some tests for `child_worker` that are not in child processes,
and we're currently leaking signal handlers. Use a context manager to
add/cancel the signal handler.
Fixes#88742
There are some tests for `child_worker` that are not in child processes,
and we're currently leaking signal handlers. Use a context manager to
add/cancel the signal handler.
Fixes#88742
when applied can result in tests failing
The text was updated successfully, but these errors were encountered: