|
1 | 1 | import os
|
| 2 | +import re |
2 | 3 | import sys
|
3 | 4 | import textwrap
|
4 | 5 |
|
|
13 | 14 |
|
14 | 15 | timeout = 15
|
15 | 16 |
|
| 17 | +pytest_version = tuple( |
| 18 | + int(segment) |
| 19 | + for segment in pytest.__version__.split(".")[:3] |
| 20 | +) |
| 21 | + |
16 | 22 |
|
17 | 23 | # https://github.com/pytest-dev/pytest/issues/6505
|
18 | 24 | def force_plural(name):
|
@@ -1179,3 +1185,73 @@ def test_succeed():
|
1179 | 1185 | testdir.makepyfile(test_file)
|
1180 | 1186 | rr = testdir.run(*cmd_opts, timeout=timeout)
|
1181 | 1187 | rr.stdout.fnmatch_lines(lines2=[test_string])
|
| 1188 | + |
| 1189 | + |
| 1190 | +def test_sigint_for_regular_tests(testdir, cmd_opts): |
| 1191 | + test_file = """ |
| 1192 | + import os |
| 1193 | + import signal |
| 1194 | + import time |
| 1195 | +
|
| 1196 | + import twisted.internet |
| 1197 | + import twisted.internet.task |
| 1198 | +
|
| 1199 | + def test_self_cancel(): |
| 1200 | + os.kill(os.getpid(), signal.SIGINT) |
| 1201 | + time.sleep(10) |
| 1202 | +
|
| 1203 | + def test_should_not_run(): |
| 1204 | + assert False |
| 1205 | + """ |
| 1206 | + testdir.makepyfile(test_file) |
| 1207 | + rr = testdir.run(*cmd_opts, timeout=timeout) |
| 1208 | + if sys.platform != "win32": |
| 1209 | + # on Windows pytest isn't even reporting the status, just stopping... |
| 1210 | + assert_outcomes(rr, {}) |
| 1211 | + rr.stdout.re_match_lines(lines2=[r".* no tests ran in .*"]) |
| 1212 | + |
| 1213 | + pattern = r".*test_should_not_run.*" |
| 1214 | + |
| 1215 | + if pytest_version >= (5, 3, 0): |
| 1216 | + rr.stdout.no_re_match_line(pat=pattern) |
| 1217 | + else: |
| 1218 | + assert re.match(pattern, rr.stdout.str()) is None |
| 1219 | + |
| 1220 | + |
| 1221 | +def test_sigint_for_inline_callbacks_tests(testdir, cmd_opts): |
| 1222 | + test_file = """ |
| 1223 | + import os |
| 1224 | + import signal |
| 1225 | +
|
| 1226 | + import twisted.internet |
| 1227 | + import twisted.internet.task |
| 1228 | +
|
| 1229 | + import pytest_twisted |
| 1230 | +
|
| 1231 | + @pytest_twisted.inlineCallbacks |
| 1232 | + def test_self_cancel(): |
| 1233 | + os.kill(os.getpid(), signal.SIGINT) |
| 1234 | + yield twisted.internet.task.deferLater( |
| 1235 | + twisted.internet.reactor, |
| 1236 | + 9999, |
| 1237 | + lambda: None, |
| 1238 | + ) |
| 1239 | +
|
| 1240 | + @pytest_twisted.inlineCallbacks |
| 1241 | + def test_should_not_run(): |
| 1242 | + assert False |
| 1243 | + yield |
| 1244 | + """ |
| 1245 | + testdir.makepyfile(test_file) |
| 1246 | + rr = testdir.run(*cmd_opts, timeout=timeout) |
| 1247 | + if sys.platform != "win32": |
| 1248 | + # on Windows pytest isn't even reporting the status, just stopping... |
| 1249 | + assert_outcomes(rr, {}) |
| 1250 | + rr.stdout.re_match_lines(lines2=[r".* no tests ran in .*"]) |
| 1251 | + |
| 1252 | + pattern = r".*test_should_not_run.*" |
| 1253 | + |
| 1254 | + if pytest_version >= (5, 3, 0): |
| 1255 | + rr.stdout.no_re_match_line(pat=pattern) |
| 1256 | + else: |
| 1257 | + assert re.match(pattern, rr.stdout.str()) is None |
0 commit comments