Skip to content

Commit 09ee9b9

Browse files
committed
timeouts
1 parent 42eaa31 commit 09ee9b9

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

testing/test_basic.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
# https://docs.python.org/3/whatsnew/3.6.html#pep-525-asynchronous-generators
1111
ASYNC_GENERATORS = sys.version_info >= (3, 6)
1212

13+
timeout = 15
14+
1315

1416
# https://github.com/pytest-dev/pytest/issues/6505
1517
def force_plural(name):
@@ -117,7 +119,7 @@ def f():
117119
yield 42
118120
""".format(import_path=import_path, decorator=decorator)
119121
testdir.makepyfile(test_file)
120-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
122+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
121123

122124
expected_outcomes = {"passed": 1}
123125
if should_warn:
@@ -161,7 +163,7 @@ def test_succeed(foo):
161163
pass
162164
""".format(import_path=import_path, function=function)
163165
testdir.makepyfile(test_file)
164-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
166+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
165167

166168
expected_outcomes = {"passed": 1}
167169
if should_warn:
@@ -186,7 +188,7 @@ def doit():
186188
return d
187189
"""
188190
testdir.makepyfile(test_file)
189-
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts)
191+
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts, timeout=timeout)
190192
assert_outcomes(rr, {"failed": 1})
191193

192194

@@ -200,7 +202,7 @@ def test_succeed():
200202
return d
201203
"""
202204
testdir.makepyfile(test_file)
203-
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts)
205+
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts, timeout=timeout)
204206
assert_outcomes(rr, {"passed": 1})
205207

206208

@@ -212,7 +214,7 @@ def test_succeed():
212214
return 42
213215
"""
214216
testdir.makepyfile(test_file)
215-
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts)
217+
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts, timeout=timeout)
216218
assert_outcomes(rr, {"passed": 1})
217219

218220

@@ -222,7 +224,7 @@ def test_more_fail():
222224
raise RuntimeError("foo")
223225
"""
224226
testdir.makepyfile(test_file)
225-
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts)
227+
rr = testdir.run(sys.executable, "-m", "pytest", *cmd_opts, timeout=timeout)
226228
assert_outcomes(rr, {"failed": 1})
227229

228230

@@ -243,7 +245,7 @@ def test_succeed(foo):
243245
raise RuntimeError("baz")
244246
"""
245247
testdir.makepyfile(test_file)
246-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
248+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
247249
assert_outcomes(rr, {"passed": 2, "failed": 1})
248250

249251

@@ -265,7 +267,7 @@ async def test_succeed(foo):
265267
raise RuntimeError("baz")
266268
"""
267269
testdir.makepyfile(test_file)
268-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
270+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
269271
assert_outcomes(rr, {"passed": 2, "failed": 1})
270272

271273

@@ -285,7 +287,7 @@ def test_MAIN():
285287
assert MAIN is greenlet.getcurrent()
286288
"""
287289
testdir.makepyfile(test_file)
288-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
290+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
289291
assert_outcomes(rr, {"passed": 1})
290292

291293

@@ -310,7 +312,7 @@ def test_succeed(foo):
310312
raise RuntimeError("baz")
311313
"""
312314
testdir.makepyfile(test_file)
313-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
315+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
314316
assert_outcomes(rr, {"passed": 2, "failed": 1})
315317

316318

@@ -336,7 +338,7 @@ async def test_succeed(foo):
336338
raise RuntimeError("baz")
337339
"""
338340
testdir.makepyfile(test_file)
339-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
341+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
340342
assert_outcomes(rr, {"passed": 2, "failed": 1})
341343

342344

@@ -372,7 +374,7 @@ def test_succeed_blue(foo):
372374
raise RuntimeError("baz")
373375
"""
374376
testdir.makepyfile(test_file)
375-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
377+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
376378
assert_outcomes(rr, {"passed": 2, "failed": 1})
377379

378380

@@ -409,7 +411,7 @@ def test_succeed(this, that):
409411
testdir.makepyfile(test_file)
410412
# TODO: add a timeout, failure just hangs indefinitely for now
411413
# https://github.com/pytest-dev/pytest/issues/4073
412-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
414+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
413415
assert_outcomes(rr, {"passed": 1})
414416

415417

@@ -448,7 +450,7 @@ def test_succeed(foo):
448450
raise RuntimeError("baz")
449451
"""
450452
testdir.makepyfile(test_file)
451-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
453+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
452454
# TODO: this is getting super imprecise...
453455
assert_outcomes(rr, {"passed": 4, "failed": 1, "errors": 2})
454456

@@ -497,7 +499,7 @@ def test_second(foo):
497499
check_me = 2
498500
"""
499501
testdir.makepyfile(test_file)
500-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
502+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
501503
assert_outcomes(rr, {"passed": 2})
502504

503505

@@ -526,7 +528,7 @@ async def test_doublefour(doublefour):
526528
assert doublefour == 8
527529
"""
528530
testdir.makepyfile(test_file)
529-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
531+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
530532
assert_outcomes(rr, {"passed": 2})
531533

532534

@@ -555,7 +557,7 @@ async def test_doublefour(doublefour):
555557
assert doublefour == 8
556558
"""
557559
testdir.makepyfile(test_file)
558-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
560+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
559561
assert_outcomes(rr, {"passed": 2})
560562

561563

@@ -602,7 +604,7 @@ async def test_doubleincrement(doubleincrement):
602604
assert (first, second) == (0, 2)
603605
""".format(maybe_async=maybe_async, maybe_await=maybe_await)
604606
testdir.makepyfile(test_file)
605-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
607+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
606608
assert_outcomes(rr, {"passed": 2})
607609
# assert_outcomes(rr, {"passed": 1})
608610

@@ -650,7 +652,7 @@ async def test_doubleincrement(doubleincrement):
650652
assert (first, second) == (0, 2)
651653
""".format(maybe_async=maybe_async, maybe_await=maybe_await)
652654
testdir.makepyfile(test_file)
653-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
655+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
654656
assert_outcomes(rr, {"passed": 2})
655657

656658

@@ -678,7 +680,7 @@ def test_succeed():
678680
return d
679681
"""
680682
testdir.makepyfile(test_file)
681-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
683+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
682684
assert_outcomes(rr, {"passed": 1})
683685

684686

@@ -695,7 +697,7 @@ def test_succeed():
695697
pass
696698
"""
697699
testdir.makepyfile(test_file)
698-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
700+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
699701
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
700702

701703

@@ -725,7 +727,7 @@ def test_succeed():
725727
return d
726728
"""
727729
testdir.makepyfile(test_file)
728-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
730+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
729731
assert_outcomes(rr, {"passed": 1})
730732

731733

@@ -742,7 +744,7 @@ def test_succeed():
742744
pass
743745
"""
744746
testdir.makepyfile(test_file)
745-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
747+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
746748
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
747749

748750

@@ -794,10 +796,10 @@ def main():
794796
"""
795797
testdir.makepyfile(runner=runner_file)
796798
# check test file is ok in standalone mode:
797-
rr = testdir.run(sys.executable, "-m", "pytest", "-v")
799+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", timeout=timeout)
798800
assert_outcomes(rr, {"passed": 1, "failed": 1})
799801
# test embedded mode:
800-
assert testdir.run(sys.executable, "runner.py").ret == 0
802+
assert testdir.run(sys.executable, "runner.py", timeout=timeout).ret == 0
801803

802804

803805
def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
@@ -829,7 +831,7 @@ def test_succeed():
829831
return d
830832
"""
831833
testdir.makepyfile(test_file)
832-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
834+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
833835
assert_outcomes(rr, {"passed": 1})
834836

835837

@@ -854,7 +856,7 @@ def test_succeed():
854856
pass
855857
"""
856858
testdir.makepyfile(test_file)
857-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
859+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
858860
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
859861

860862

@@ -902,5 +904,5 @@ def test_second(foo):
902904
check_me = 3
903905
"""
904906
testdir.makepyfile(test_file)
905-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
907+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts, timeout=timeout)
906908
assert_outcomes(rr, {"passed": 2})

0 commit comments

Comments
 (0)