Skip to content

Commit f6c7e6d

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

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

python/cocoindex/tests/conftest.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,40 @@
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."""
13+
14+
print("Platform: ", sys.platform)
1015

1116
yield
1217

18+
if not sys.platform.startswith("win"):
19+
return
20+
1321
try:
1422
print("Shutdown the subprocess pool at exit in hook.")
1523
import cocoindex.subprocess_exec
1624

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:
25+
original_sigint_handler = signal.getsignal(signal.SIGINT)
26+
try:
27+
signal.signal(signal.SIGINT, signal.SIG_IGN)
2828
cocoindex.subprocess_exec.shutdown_pool_at_exit()
29+
30+
# If any test failed, let pytest exit normally with nonzero code
31+
if request.session.testsfailed == 0:
32+
os._exit(0) # immediate success exit (skips atexit/teardown)
33+
34+
finally:
35+
try:
36+
signal.signal(signal.SIGINT, original_sigint_handler)
37+
except ValueError: # noqa: BLE001
38+
pass
39+
2940
except (ImportError, AttributeError): # noqa: BLE001
3041
pass

0 commit comments

Comments
 (0)