1010# https://docs.python.org/3/whatsnew/3.6.html#pep-525-asynchronous-generators
1111ASYNC_GENERATORS = sys .version_info >= (3 , 6 )
1212
13+ timeout = 15
14+
1315
1416# https://github.com/pytest-dev/pytest/issues/6505
1517def force_plural (name ):
@@ -87,7 +89,13 @@ def skip_if_no_async_generators():
8789@pytest .fixture
8890def cmd_opts (request ):
8991 reactor = request .config .getoption ("reactor" , "default" )
90- return ("--reactor={}" .format (reactor ),)
92+ return (
93+ sys .executable ,
94+ "-m" ,
95+ "pytest" ,
96+ "-v" ,
97+ "--reactor={}" .format (reactor ),
98+ )
9199
92100
93101def test_inline_callbacks_in_pytest ():
@@ -117,7 +125,7 @@ def f():
117125 yield 42
118126 """ .format (import_path = import_path , decorator = decorator )
119127 testdir .makepyfile (test_file )
120- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
128+ rr = testdir .run (* cmd_opts , timeout = timeout )
121129
122130 expected_outcomes = {"passed" : 1 }
123131 if should_warn :
@@ -161,7 +169,7 @@ def test_succeed(foo):
161169 pass
162170 """ .format (import_path = import_path , function = function )
163171 testdir .makepyfile (test_file )
164- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
172+ rr = testdir .run (* cmd_opts , timeout = timeout )
165173
166174 expected_outcomes = {"passed" : 1 }
167175 if should_warn :
@@ -186,7 +194,7 @@ def doit():
186194 return d
187195 """
188196 testdir .makepyfile (test_file )
189- rr = testdir .run (sys . executable , "-m" , "pytest" , * cmd_opts )
197+ rr = testdir .run (* cmd_opts , timeout = timeout )
190198 assert_outcomes (rr , {"failed" : 1 })
191199
192200
@@ -200,7 +208,7 @@ def test_succeed():
200208 return d
201209 """
202210 testdir .makepyfile (test_file )
203- rr = testdir .run (sys . executable , "-m" , "pytest" , * cmd_opts )
211+ rr = testdir .run (* cmd_opts , timeout = timeout )
204212 assert_outcomes (rr , {"passed" : 1 })
205213
206214
@@ -212,7 +220,7 @@ def test_succeed():
212220 return 42
213221 """
214222 testdir .makepyfile (test_file )
215- rr = testdir .run (sys . executable , "-m" , "pytest" , * cmd_opts )
223+ rr = testdir .run (* cmd_opts , timeout = timeout )
216224 assert_outcomes (rr , {"passed" : 1 })
217225
218226
@@ -222,7 +230,7 @@ def test_more_fail():
222230 raise RuntimeError("foo")
223231 """
224232 testdir .makepyfile (test_file )
225- rr = testdir .run (sys . executable , "-m" , "pytest" , * cmd_opts )
233+ rr = testdir .run (* cmd_opts , timeout = timeout )
226234 assert_outcomes (rr , {"failed" : 1 })
227235
228236
@@ -243,7 +251,7 @@ def test_succeed(foo):
243251 raise RuntimeError("baz")
244252 """
245253 testdir .makepyfile (test_file )
246- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
254+ rr = testdir .run (* cmd_opts , timeout = timeout )
247255 assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
248256
249257
@@ -265,7 +273,7 @@ async def test_succeed(foo):
265273 raise RuntimeError("baz")
266274 """
267275 testdir .makepyfile (test_file )
268- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
276+ rr = testdir .run (* cmd_opts , timeout = timeout )
269277 assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
270278
271279
@@ -285,7 +293,7 @@ def test_MAIN():
285293 assert MAIN is greenlet.getcurrent()
286294 """
287295 testdir .makepyfile (test_file )
288- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
296+ rr = testdir .run (* cmd_opts , timeout = timeout )
289297 assert_outcomes (rr , {"passed" : 1 })
290298
291299
@@ -310,7 +318,7 @@ def test_succeed(foo):
310318 raise RuntimeError("baz")
311319 """
312320 testdir .makepyfile (test_file )
313- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
321+ rr = testdir .run (* cmd_opts , timeout = timeout )
314322 assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
315323
316324
@@ -336,7 +344,7 @@ async def test_succeed(foo):
336344 raise RuntimeError("baz")
337345 """
338346 testdir .makepyfile (test_file )
339- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
347+ rr = testdir .run (* cmd_opts , timeout = timeout )
340348 assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
341349
342350
@@ -372,7 +380,7 @@ def test_succeed_blue(foo):
372380 raise RuntimeError("baz")
373381 """
374382 testdir .makepyfile (test_file )
375- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
383+ rr = testdir .run (* cmd_opts , timeout = timeout )
376384 assert_outcomes (rr , {"passed" : 2 , "failed" : 1 })
377385
378386
@@ -409,7 +417,7 @@ def test_succeed(this, that):
409417 testdir .makepyfile (test_file )
410418 # TODO: add a timeout, failure just hangs indefinitely for now
411419 # https://github.com/pytest-dev/pytest/issues/4073
412- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
420+ rr = testdir .run (* cmd_opts , timeout = timeout )
413421 assert_outcomes (rr , {"passed" : 1 })
414422
415423
@@ -448,7 +456,7 @@ def test_succeed(foo):
448456 raise RuntimeError("baz")
449457 """
450458 testdir .makepyfile (test_file )
451- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
459+ rr = testdir .run (* cmd_opts , timeout = timeout )
452460 # TODO: this is getting super imprecise...
453461 assert_outcomes (rr , {"passed" : 4 , "failed" : 1 , "errors" : 2 })
454462
@@ -497,7 +505,7 @@ def test_second(foo):
497505 check_me = 2
498506 """
499507 testdir .makepyfile (test_file )
500- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
508+ rr = testdir .run (* cmd_opts , timeout = timeout )
501509 assert_outcomes (rr , {"passed" : 2 })
502510
503511
@@ -526,7 +534,7 @@ async def test_doublefour(doublefour):
526534 assert doublefour == 8
527535 """
528536 testdir .makepyfile (test_file )
529- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
537+ rr = testdir .run (* cmd_opts , timeout = timeout )
530538 assert_outcomes (rr , {"passed" : 2 })
531539
532540
@@ -555,7 +563,7 @@ async def test_doublefour(doublefour):
555563 assert doublefour == 8
556564 """
557565 testdir .makepyfile (test_file )
558- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
566+ rr = testdir .run (* cmd_opts , timeout = timeout )
559567 assert_outcomes (rr , {"passed" : 2 })
560568
561569
@@ -602,7 +610,7 @@ async def test_doubleincrement(doubleincrement):
602610 assert (first, second) == (0, 2)
603611 """ .format (maybe_async = maybe_async , maybe_await = maybe_await )
604612 testdir .makepyfile (test_file )
605- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
613+ rr = testdir .run (* cmd_opts , timeout = timeout )
606614 assert_outcomes (rr , {"passed" : 2 })
607615 # assert_outcomes(rr, {"passed": 1})
608616
@@ -650,7 +658,7 @@ async def test_doubleincrement(doubleincrement):
650658 assert (first, second) == (0, 2)
651659 """ .format (maybe_async = maybe_async , maybe_await = maybe_await )
652660 testdir .makepyfile (test_file )
653- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
661+ rr = testdir .run (* cmd_opts , timeout = timeout )
654662 assert_outcomes (rr , {"passed" : 2 })
655663
656664
@@ -678,7 +686,7 @@ def test_succeed():
678686 return d
679687 """
680688 testdir .makepyfile (test_file )
681- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
689+ rr = testdir .run (* cmd_opts , timeout = timeout )
682690 assert_outcomes (rr , {"passed" : 1 })
683691
684692
@@ -695,7 +703,7 @@ def test_succeed():
695703 pass
696704 """
697705 testdir .makepyfile (test_file )
698- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
706+ rr = testdir .run (* cmd_opts , timeout = timeout )
699707 assert "WrongReactorAlreadyInstalledError" in rr .stderr .str ()
700708
701709
@@ -725,7 +733,7 @@ def test_succeed():
725733 return d
726734 """
727735 testdir .makepyfile (test_file )
728- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
736+ rr = testdir .run (* cmd_opts , timeout = timeout )
729737 assert_outcomes (rr , {"passed" : 1 })
730738
731739
@@ -742,11 +750,11 @@ def test_succeed():
742750 pass
743751 """
744752 testdir .makepyfile (test_file )
745- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
753+ rr = testdir .run (* cmd_opts , timeout = timeout )
746754 assert "WrongReactorAlreadyInstalledError" in rr .stderr .str ()
747755
748756
749- def test_pytest_from_reactor_thread (testdir , request ):
757+ def test_pytest_from_reactor_thread (testdir , cmd_opts , request ):
750758 skip_if_reactor_not (request , "default" )
751759 test_file = """
752760 import pytest
@@ -794,10 +802,10 @@ def main():
794802 """
795803 testdir .makepyfile (runner = runner_file )
796804 # check test file is ok in standalone mode:
797- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" )
805+ rr = testdir .run (* cmd_opts , timeout = timeout )
798806 assert_outcomes (rr , {"passed" : 1 , "failed" : 1 })
799807 # test embedded mode:
800- assert testdir .run (sys .executable , "runner.py" ).ret == 0
808+ assert testdir .run (sys .executable , "runner.py" , timeout = timeout ).ret == 0
801809
802810
803811def test_blockon_in_hook_with_asyncio (testdir , cmd_opts , request ):
@@ -829,7 +837,7 @@ def test_succeed():
829837 return d
830838 """
831839 testdir .makepyfile (test_file )
832- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
840+ rr = testdir .run (* cmd_opts , timeout = timeout )
833841 assert_outcomes (rr , {"passed" : 1 })
834842
835843
@@ -854,7 +862,7 @@ def test_succeed():
854862 pass
855863 """
856864 testdir .makepyfile (test_file )
857- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
865+ rr = testdir .run (* cmd_opts , timeout = timeout )
858866 assert "WrongReactorAlreadyInstalledError" in rr .stderr .str ()
859867
860868
@@ -902,5 +910,5 @@ def test_second(foo):
902910 check_me = 3
903911 """
904912 testdir .makepyfile (test_file )
905- rr = testdir .run (sys . executable , "-m" , "pytest" , "-v" , * cmd_opts )
913+ rr = testdir .run (* cmd_opts , timeout = timeout )
906914 assert_outcomes (rr , {"passed" : 2 })
0 commit comments