Skip to content

Commit e40a6de

Browse files
committed
add test for shutdown event callbacks
1 parent cc03b11 commit e40a6de

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

testing/test_basic.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,3 +1138,33 @@ 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+
@pytest.mark.parametrize(argnames="kill", argvalues=[False, True])
1144+
@pytest.mark.parametrize(argnames="event", argvalues=["shutdown"])
1145+
@pytest.mark.parametrize(argnames="phase", argvalues=["before", "during", "after"])
1146+
def test_addSystemEventTrigger(testdir, cmd_opts, kill, event, phase):
1147+
test_string = "1kljgf90u0lkj13l4jjklsfdo89898y24hlkjalkjs38"
1148+
1149+
test_file = """
1150+
import os
1151+
1152+
import pytest_twisted
1153+
1154+
def output_stuff():
1155+
print({test_string!r})
1156+
1157+
@pytest_twisted.inlineCallbacks
1158+
def test_succeed():
1159+
from twisted.internet import reactor
1160+
reactor.addSystemEventTrigger(phase={phase!r}, eventType={event!r}, callable=output_stuff)
1161+
1162+
if {kill!r}:
1163+
os.kill(os.get_pid())
1164+
1165+
yield
1166+
""".format(kill=kill, event=event, phase=phase, test_string=test_string)
1167+
testdir.makepyfile(test_file)
1168+
rr = testdir.run(*cmd_opts, timeout=timeout)
1169+
assert_outcomes(rr, {"passed": 1})
1170+
rr.stdout.fnmatch_lines(lines2=[test_string])

0 commit comments

Comments
 (0)