Skip to content

Commit 5d62ce3

Browse files
authored
Merge branch 'master' into optional_call_for_decorators
2 parents 3a11f26 + 23e60b9 commit 5d62ce3

File tree

3 files changed

+49
-33
lines changed

3 files changed

+49
-33
lines changed

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
BSD 3-Clause License
22

33
Copyright (c) 2012, Ralf Schmitt
4+
Copyright (c) 2018, Victor Titor
5+
Copyright (c) 2019-2020, Kyle Altendorf
46
All rights reserved.
57

68
Redistribution and use in source and binary forms, with or without

pytest_twisted.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import greenlet
88
import pytest
99

10-
from twisted.internet import error, defer
10+
from twisted.internet import defer
11+
# from twisted.internet import error
1112
from twisted.internet.threads import blockingCallFromThread
1213
from twisted.python import failure
1314

@@ -422,9 +423,14 @@ def init_asyncio_reactor():
422423

423424
def _install_reactor(reactor_installer, reactor_type):
424425
"""Install the specified reactor and create the greenlet."""
425-
try:
426+
# TODO: maybe fix this in qt5reactor? btw, it avoids creating a second
427+
# qt5reactor.core.QtEventReactor and this somehow fixes the hang
428+
# that showed up in 5.15.0.
429+
# try:
430+
if 'twisted.internet.reactor' not in sys.modules:
426431
reactor_installer()
427-
except error.ReactorAlreadyInstalledError:
432+
# except error.ReactorAlreadyInstalledError:
433+
else:
428434
import twisted.internet.reactor
429435

430436
if not isinstance(twisted.internet.reactor, reactor_type):

testing/test_basic.py

Lines changed: 38 additions & 30 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):
@@ -87,7 +89,13 @@ def skip_if_no_async_generators():
8789
@pytest.fixture
8890
def 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

93101
def 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

@@ -252,7 +260,7 @@ def test_succeed(foo):
252260
raise RuntimeError("baz")
253261
""".format(optional_call=empty_optional_call)
254262
testdir.makepyfile(test_file)
255-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
263+
rr = testdir.run(*cmd_opts, timeout=timeout)
256264
assert_outcomes(rr, {"passed": 2, "failed": 1})
257265

258266

@@ -274,7 +282,7 @@ async def test_succeed(foo):
274282
raise RuntimeError("baz")
275283
""".format(optional_call=empty_optional_call)
276284
testdir.makepyfile(test_file)
277-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
285+
rr = testdir.run(*cmd_opts, timeout=timeout)
278286
assert_outcomes(rr, {"passed": 2, "failed": 1})
279287

280288

@@ -294,7 +302,7 @@ def test_MAIN():
294302
assert MAIN is greenlet.getcurrent()
295303
"""
296304
testdir.makepyfile(test_file)
297-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
305+
rr = testdir.run(*cmd_opts, timeout=timeout)
298306
assert_outcomes(rr, {"passed": 1})
299307

300308

@@ -319,7 +327,7 @@ def test_succeed(foo):
319327
raise RuntimeError("baz")
320328
"""
321329
testdir.makepyfile(test_file)
322-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
330+
rr = testdir.run(*cmd_opts, timeout=timeout)
323331
assert_outcomes(rr, {"passed": 2, "failed": 1})
324332

325333

@@ -345,7 +353,7 @@ async def test_succeed(foo):
345353
raise RuntimeError("baz")
346354
"""
347355
testdir.makepyfile(test_file)
348-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
356+
rr = testdir.run(*cmd_opts, timeout=timeout)
349357
assert_outcomes(rr, {"passed": 2, "failed": 1})
350358

351359

@@ -381,7 +389,7 @@ def test_succeed_blue(foo):
381389
raise RuntimeError("baz")
382390
"""
383391
testdir.makepyfile(test_file)
384-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
392+
rr = testdir.run(*cmd_opts, timeout=timeout)
385393
assert_outcomes(rr, {"passed": 2, "failed": 1})
386394

387395

@@ -437,7 +445,7 @@ def test_succeed(this, that):
437445
testdir.makepyfile(test_file)
438446
# TODO: add a timeout, failure just hangs indefinitely for now
439447
# https://github.com/pytest-dev/pytest/issues/4073
440-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
448+
rr = testdir.run(*cmd_opts, timeout=timeout)
441449
assert_outcomes(rr, {"passed": 1})
442450

443451

@@ -476,7 +484,7 @@ def test_succeed(foo):
476484
raise RuntimeError("baz")
477485
"""
478486
testdir.makepyfile(test_file)
479-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
487+
rr = testdir.run(*cmd_opts, timeout=timeout)
480488
# TODO: this is getting super imprecise...
481489
assert_outcomes(rr, {"passed": 4, "failed": 1, "errors": 2})
482490

@@ -548,7 +556,7 @@ def test_second(foo):
548556
check_me = 2
549557
"""
550558
testdir.makepyfile(test_file)
551-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
559+
rr = testdir.run(*cmd_opts, timeout=timeout)
552560
assert_outcomes(rr, {"passed": 2})
553561

554562

@@ -577,7 +585,7 @@ async def test_doublefour(doublefour):
577585
assert doublefour == 8
578586
"""
579587
testdir.makepyfile(test_file)
580-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
588+
rr = testdir.run(*cmd_opts, timeout=timeout)
581589
assert_outcomes(rr, {"passed": 2})
582590

583591

@@ -606,7 +614,7 @@ async def test_doublefour(doublefour):
606614
assert doublefour == 8
607615
"""
608616
testdir.makepyfile(test_file)
609-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
617+
rr = testdir.run(*cmd_opts, timeout=timeout)
610618
assert_outcomes(rr, {"passed": 2})
611619

612620

@@ -653,7 +661,7 @@ async def test_doubleincrement(doubleincrement):
653661
assert (first, second) == (0, 2)
654662
""".format(maybe_async=maybe_async, maybe_await=maybe_await)
655663
testdir.makepyfile(test_file)
656-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
664+
rr = testdir.run(*cmd_opts, timeout=timeout)
657665
assert_outcomes(rr, {"passed": 2})
658666
# assert_outcomes(rr, {"passed": 1})
659667

@@ -701,7 +709,7 @@ async def test_doubleincrement(doubleincrement):
701709
assert (first, second) == (0, 2)
702710
""".format(maybe_async=maybe_async, maybe_await=maybe_await)
703711
testdir.makepyfile(test_file)
704-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
712+
rr = testdir.run(*cmd_opts, timeout=timeout)
705713
assert_outcomes(rr, {"passed": 2})
706714

707715

@@ -729,7 +737,7 @@ def test_succeed():
729737
return d
730738
"""
731739
testdir.makepyfile(test_file)
732-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
740+
rr = testdir.run(*cmd_opts, timeout=timeout)
733741
assert_outcomes(rr, {"passed": 1})
734742

735743

@@ -746,7 +754,7 @@ def test_succeed():
746754
pass
747755
"""
748756
testdir.makepyfile(test_file)
749-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
757+
rr = testdir.run(*cmd_opts, timeout=timeout)
750758
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
751759

752760

@@ -776,7 +784,7 @@ def test_succeed():
776784
return d
777785
"""
778786
testdir.makepyfile(test_file)
779-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
787+
rr = testdir.run(*cmd_opts, timeout=timeout)
780788
assert_outcomes(rr, {"passed": 1})
781789

782790

@@ -793,11 +801,11 @@ def test_succeed():
793801
pass
794802
"""
795803
testdir.makepyfile(test_file)
796-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
804+
rr = testdir.run(*cmd_opts, timeout=timeout)
797805
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
798806

799807

800-
def test_pytest_from_reactor_thread(testdir, request):
808+
def test_pytest_from_reactor_thread(testdir, cmd_opts, request):
801809
skip_if_reactor_not(request, "default")
802810
test_file = """
803811
import pytest
@@ -845,10 +853,10 @@ def main():
845853
"""
846854
testdir.makepyfile(runner=runner_file)
847855
# check test file is ok in standalone mode:
848-
rr = testdir.run(sys.executable, "-m", "pytest", "-v")
856+
rr = testdir.run(*cmd_opts, timeout=timeout)
849857
assert_outcomes(rr, {"passed": 1, "failed": 1})
850858
# test embedded mode:
851-
assert testdir.run(sys.executable, "runner.py").ret == 0
859+
assert testdir.run(sys.executable, "runner.py", timeout=timeout).ret == 0
852860

853861

854862
def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
@@ -880,7 +888,7 @@ def test_succeed():
880888
return d
881889
"""
882890
testdir.makepyfile(test_file)
883-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
891+
rr = testdir.run(*cmd_opts, timeout=timeout)
884892
assert_outcomes(rr, {"passed": 1})
885893

886894

@@ -905,7 +913,7 @@ def test_succeed():
905913
pass
906914
"""
907915
testdir.makepyfile(test_file)
908-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
916+
rr = testdir.run(*cmd_opts, timeout=timeout)
909917
assert "WrongReactorAlreadyInstalledError" in rr.stderr.str()
910918

911919

@@ -953,5 +961,5 @@ def test_second(foo):
953961
check_me = 3
954962
"""
955963
testdir.makepyfile(test_file)
956-
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
964+
rr = testdir.run(*cmd_opts, timeout=timeout)
957965
assert_outcomes(rr, {"passed": 2})

0 commit comments

Comments
 (0)