File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ on: [push, pull_request]
55jobs :
66 build :
77 runs-on : ubuntu-latest
8+ timeout-minutes : 5
89 services :
910 rabbitmq :
1011 image : rabbitmq
3435 run : uv run basedpyright
3536 - name : Run tests
3637 run : uv run pytest
38+ timeout-minutes : 2
Original file line number Diff line number Diff line change @@ -55,6 +55,9 @@ register = [
5555broker = " pika://localhost:5672"
5656journal = " pika://localhost:5672"
5757
58+ [tool .pytest .ini_options ]
59+ timeout = 30
60+
5861[tool .coverage .run ]
5962branch = true
6063source = [" queueio" ]
Original file line number Diff line number Diff line change 1+ import os
2+ import threading
3+ from threading import Thread
4+ from time import sleep
5+
6+ import pytest
7+
8+
9+ def pytest_sessionstart (session ):
10+ """Ensure the test suite always exits."""
11+ timeout = float (session .config .getini ("timeout" )) + 5
12+ Thread (target = lambda : sleep (timeout ) or os ._exit (1 ), daemon = True ).start ()
13+
14+
15+ @pytest .fixture (autouse = True )
16+ def check_thread_cleanup ():
17+ """Ensure that threads are not left running."""
18+ initial_threads = set (threading .enumerate ())
19+ yield
20+ final_threads = {t for t in threading .enumerate () if t .is_alive ()}
21+ new_threads = final_threads - initial_threads
22+
23+ if new_threads :
24+ thread_info = []
25+ for thread in new_threads :
26+ daemon = "daemon" if thread .daemon else "non-daemon"
27+ thread_info .append (f" - { thread .name } ({ daemon } )" )
28+
29+ pytest .fail (
30+ f"Test left { len (new_threads )} thread(s) running:\n "
31+ + "\n " .join (thread_info )
32+ )
You can’t perform that action at this time.
0 commit comments