Skip to content

Commit 789adb7

Browse files
committed
disable reactor's signal handlers
1 parent cc03b11 commit 789adb7

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

pytest_twisted.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ def init_twisted_greenlet():
199199
return
200200

201201
if not _instances.reactor.running:
202-
_instances.gr_twisted = greenlet.greenlet(_instances.reactor.run)
202+
_instances.gr_twisted = greenlet.greenlet(
203+
lambda: _instances.reactor.run(installSignalHandlers=False),
204+
)
203205
# give me better tracebacks:
204206
failure.Failure.cleanFailure = lambda self: None
205207
else:

testing/test_basic.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,3 +1138,55 @@ def test_succeed():
11381138
testdir.makepyfile(test_file)
11391139
rr = testdir.run(*cmd_opts, timeout=timeout)
11401140
assert_outcomes(rr, {"passed": 1})
1141+
1142+
1143+
def test_sigint_for_regular_tests(testdir, cmd_opts):
1144+
test_file = """
1145+
import os
1146+
import signal
1147+
import time
1148+
1149+
import twisted.internet
1150+
import twisted.internet.task
1151+
1152+
def test_self_cancel():
1153+
os.kill(os.getpid(), signal.SIGINT)
1154+
time.sleep(10)
1155+
1156+
def test_should_not_run():
1157+
assert False
1158+
"""
1159+
testdir.makepyfile(test_file)
1160+
rr = testdir.run(*cmd_opts, timeout=timeout)
1161+
assert_outcomes(rr, {})
1162+
rr.stdout.re_match_lines(lines2=[r".* no tests ran in .*"])
1163+
1164+
1165+
def test_sigint_for_inline_callbacks_tests(testdir, cmd_opts):
1166+
test_file = """
1167+
import os
1168+
import signal
1169+
1170+
import twisted.internet
1171+
import twisted.internet.task
1172+
1173+
import pytest_twisted
1174+
1175+
@pytest_twisted.inlineCallbacks
1176+
def test_self_cancel():
1177+
os.kill(os.getpid(), signal.SIGINT)
1178+
yield twisted.internet.task.deferLater(
1179+
twisted.internet.reactor,
1180+
9999,
1181+
lambda: None,
1182+
)
1183+
1184+
@pytest_twisted.inlineCallbacks
1185+
def test_should_not_run():
1186+
assert False
1187+
yield
1188+
"""
1189+
testdir.makepyfile(test_file)
1190+
rr = testdir.run(*cmd_opts, timeout=timeout)
1191+
assert_outcomes(rr, {})
1192+
rr.stdout.re_match_lines(lines2=[r".* no tests ran in .*"])

0 commit comments

Comments
 (0)