Skip to content

Commit 51d341f

Browse files
authored
Merge branch 'master' into optional_call_for_decorators
2 parents 8c9ada7 + 37693ec commit 51d341f

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

README.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ be explicitly installed earlier by calling
111111
``pytest_twisted.init_default_reactor()`` or the corresponding function
112112
for the desired alternate reactor.
113113

114-
Beware that in situations such as
115-
a ``conftest.py`` file that the name ``pytest_twisted`` may be
116-
undesirably detected by ``pytest`` as an unknown hook. One alternative
117-
is to ``import pytest_twisted as pt``.
118-
119114

120115
inlineCallbacks
121116
===============

testing/test_basic.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,16 +716,16 @@ async def test_doubleincrement(doubleincrement):
716716
def test_blockon_in_hook(testdir, cmd_opts, request):
717717
skip_if_reactor_not(request, "default")
718718
conftest_file = """
719-
import pytest_twisted as pt
719+
import pytest_twisted
720720
from twisted.internet import reactor, defer
721721
722722
def pytest_configure(config):
723-
pt.init_default_reactor()
723+
pytest_twisted.init_default_reactor()
724724
d1, d2 = defer.Deferred(), defer.Deferred()
725725
reactor.callLater(0.01, d1.callback, 1)
726726
reactor.callLater(0.02, d2.callback, 1)
727-
pt.blockon(d1)
728-
pt.blockon(d2)
727+
pytest_twisted.blockon(d1)
728+
pytest_twisted.blockon(d2)
729729
"""
730730
testdir.makeconftest(conftest_file)
731731
test_file = """
@@ -761,18 +761,18 @@ def test_succeed():
761761
def test_blockon_in_hook_with_qt5reactor(testdir, cmd_opts, request):
762762
skip_if_reactor_not(request, "qt5reactor")
763763
conftest_file = """
764-
import pytest_twisted as pt
764+
import pytest_twisted
765765
import pytestqt
766766
from twisted.internet import defer
767767
768768
def pytest_configure(config):
769-
pt.init_qt5_reactor()
769+
pytest_twisted.init_qt5_reactor()
770770
d = defer.Deferred()
771771
772772
from twisted.internet import reactor
773773
774774
reactor.callLater(0.01, d.callback, 1)
775-
pt.blockon(d)
775+
pytest_twisted.blockon(d)
776776
"""
777777
testdir.makeconftest(conftest_file)
778778
test_file = """
@@ -863,20 +863,20 @@ def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
863863
skip_if_reactor_not(request, "asyncio")
864864
conftest_file = """
865865
import pytest
866-
import pytest_twisted as pt
866+
import pytest_twisted
867867
from twisted.internet import defer
868868
869869
@pytest.hookimpl(tryfirst=True)
870870
def pytest_configure(config):
871-
pt._use_asyncio_selector_if_required(config=config)
871+
pytest_twisted._use_asyncio_selector_if_required(config=config)
872872
873-
pt.init_asyncio_reactor()
873+
pytest_twisted.init_asyncio_reactor()
874874
d = defer.Deferred()
875875
876876
from twisted.internet import reactor
877877
878878
reactor.callLater(0.01, d.callback, 1)
879-
pt.blockon(d)
879+
pytest_twisted.blockon(d)
880880
"""
881881
testdir.makeconftest(conftest_file)
882882
test_file = """
@@ -1047,3 +1047,25 @@ async def test_self_isinstance(self, foo):
10471047
testdir.makepyfile(test_file)
10481048
rr = testdir.run(*cmd_opts, timeout=timeout)
10491049
assert_outcomes(rr, {"passed": 1})
1050+
1051+
1052+
def test_import_pytest_twisted_in_conftest_py_not_a_problem(testdir, cmd_opts):
1053+
conftest_file = """
1054+
import pytest
1055+
import pytest_twisted
1056+
1057+
1058+
@pytest.hookimpl(tryfirst=True)
1059+
def pytest_configure(config):
1060+
pytest_twisted._use_asyncio_selector_if_required(config=config)
1061+
"""
1062+
testdir.makeconftest(conftest_file)
1063+
test_file = """
1064+
import pytest_twisted
1065+
1066+
def test_succeed():
1067+
pass
1068+
"""
1069+
testdir.makepyfile(test_file)
1070+
rr = testdir.run(*cmd_opts, timeout=timeout)
1071+
assert_outcomes(rr, {"passed": 1})

0 commit comments

Comments
 (0)