Skip to content

Commit 4877c97

Browse files
committed
fix: directly exit with 0 after tests in Windows
1 parent 35e9e24 commit 4877c97

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

python/cocoindex/tests/conftest.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@
22
import typing
33
import os
44
import signal
5+
import sys
56

67

78
@pytest.fixture(scope="session", autouse=True)
8-
def _cocoindex_env_fixture() -> typing.Generator[None, None, None]:
9-
"""Shutdown the subprocess pool at exit."""
9+
def _cocoindex_windows_env_fixture(
10+
request: pytest.FixtureRequest,
11+
) -> typing.Generator[None, None, None]:
12+
"""Shutdown the subprocess pool at exit on Windows."""
1013

1114
yield
1215

16+
if not sys.platform.startswith("win"):
17+
return
18+
1319
try:
1420
print("Shutdown the subprocess pool at exit in hook.")
1521
import cocoindex.subprocess_exec
1622

17-
if os.name == "nt":
18-
original_sigint_handler = signal.getsignal(signal.SIGINT)
19-
try:
20-
signal.signal(signal.SIGINT, signal.SIG_IGN)
21-
cocoindex.subprocess_exec.shutdown_pool_at_exit()
22-
finally:
23-
try:
24-
signal.signal(signal.SIGINT, original_sigint_handler)
25-
except ValueError: # noqa: BLE001
26-
pass
27-
else:
23+
original_sigint_handler = signal.getsignal(signal.SIGINT)
24+
try:
25+
signal.signal(signal.SIGINT, signal.SIG_IGN)
2826
cocoindex.subprocess_exec.shutdown_pool_at_exit()
27+
finally:
28+
try:
29+
signal.signal(signal.SIGINT, original_sigint_handler)
30+
except ValueError: # noqa: BLE001
31+
pass
32+
2933
except (ImportError, AttributeError): # noqa: BLE001
3034
pass
35+
36+
# If any test failed, let pytest exit normally with nonzero code
37+
if request.session.testsfailed == 0:
38+
os._exit(0) # immediate success exit (skips atexit/teardown)

0 commit comments

Comments
 (0)