Skip to content

Commit 9e83371

Browse files
authored
Merge branch 'master' into drop_qt5reactor_workaround
2 parents 34fae97 + 37693ec commit 9e83371

File tree

3 files changed

+118
-17
lines changed

3 files changed

+118
-17
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
===============

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
long_description=long_description,
1111
long_description_content_type="text/x-rst",
1212
author="Ralf Schmitt, Kyle Altendorf, Victor Titor",
13-
author_email="[email protected]",
13+
author_email="[email protected]",
1414
url="https://github.com/pytest-dev/pytest-twisted",
1515
py_modules=["pytest_twisted"],
1616
python_requires='>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*',

testing/test_basic.py

Lines changed: 117 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -665,16 +665,16 @@ async def test_doubleincrement(doubleincrement):
665665
def test_blockon_in_hook(testdir, cmd_opts, request):
666666
skip_if_reactor_not(request, "default")
667667
conftest_file = """
668-
import pytest_twisted as pt
668+
import pytest_twisted
669669
from twisted.internet import reactor, defer
670670
671671
def pytest_configure(config):
672-
pt.init_default_reactor()
672+
pytest_twisted.init_default_reactor()
673673
d1, d2 = defer.Deferred(), defer.Deferred()
674674
reactor.callLater(0.01, d1.callback, 1)
675675
reactor.callLater(0.02, d2.callback, 1)
676-
pt.blockon(d1)
677-
pt.blockon(d2)
676+
pytest_twisted.blockon(d1)
677+
pytest_twisted.blockon(d2)
678678
"""
679679
testdir.makeconftest(conftest_file)
680680
test_file = """
@@ -710,18 +710,18 @@ def test_succeed():
710710
def test_blockon_in_hook_with_qt5reactor(testdir, cmd_opts, request):
711711
skip_if_reactor_not(request, "qt5reactor")
712712
conftest_file = """
713-
import pytest_twisted as pt
713+
import pytest_twisted
714714
import pytestqt
715715
from twisted.internet import defer
716716
717717
def pytest_configure(config):
718-
pt.init_qt5_reactor()
718+
pytest_twisted.init_qt5_reactor()
719719
d = defer.Deferred()
720720
721721
from twisted.internet import reactor
722722
723723
reactor.callLater(0.01, d.callback, 1)
724-
pt.blockon(d)
724+
pytest_twisted.blockon(d)
725725
"""
726726
testdir.makeconftest(conftest_file)
727727
test_file = """
@@ -812,20 +812,20 @@ def test_blockon_in_hook_with_asyncio(testdir, cmd_opts, request):
812812
skip_if_reactor_not(request, "asyncio")
813813
conftest_file = """
814814
import pytest
815-
import pytest_twisted as pt
815+
import pytest_twisted
816816
from twisted.internet import defer
817817
818818
@pytest.hookimpl(tryfirst=True)
819819
def pytest_configure(config):
820-
pt._use_asyncio_selector_if_required(config=config)
820+
pytest_twisted._use_asyncio_selector_if_required(config=config)
821821
822-
pt.init_asyncio_reactor()
822+
pytest_twisted.init_asyncio_reactor()
823823
d = defer.Deferred()
824824
825825
from twisted.internet import reactor
826826
827827
reactor.callLater(0.01, d.callback, 1)
828-
pt.blockon(d)
828+
pytest_twisted.blockon(d)
829829
"""
830830
testdir.makeconftest(conftest_file)
831831
test_file = """
@@ -912,3 +912,109 @@ def test_second(foo):
912912
testdir.makepyfile(test_file)
913913
rr = testdir.run(*cmd_opts, timeout=timeout)
914914
assert_outcomes(rr, {"passed": 2})
915+
916+
917+
def test_inlinecallbacks_method_with_fixture_gets_self(testdir, cmd_opts):
918+
test_file = """
919+
import pytest
920+
import pytest_twisted
921+
from twisted.internet import defer
922+
923+
@pytest.fixture
924+
def foo():
925+
return 37
926+
927+
class TestClass:
928+
@pytest_twisted.inlineCallbacks
929+
def test_self_isinstance(self, foo):
930+
d = defer.succeed(None)
931+
yield d
932+
assert isinstance(self, TestClass)
933+
"""
934+
testdir.makepyfile(test_file)
935+
rr = testdir.run(*cmd_opts)
936+
assert_outcomes(rr, {"passed": 1})
937+
938+
939+
def test_inlinecallbacks_method_with_fixture_gets_fixture(testdir, cmd_opts):
940+
test_file = """
941+
import pytest
942+
import pytest_twisted
943+
from twisted.internet import defer
944+
945+
@pytest.fixture
946+
def foo():
947+
return 37
948+
949+
class TestClass:
950+
@pytest_twisted.inlineCallbacks
951+
def test_self_isinstance(self, foo):
952+
d = defer.succeed(None)
953+
yield d
954+
assert foo == 37
955+
"""
956+
testdir.makepyfile(test_file)
957+
rr = testdir.run(*cmd_opts, timeout=timeout)
958+
assert_outcomes(rr, {"passed": 1})
959+
960+
961+
@skip_if_no_async_await()
962+
def test_ensuredeferred_method_with_fixture_gets_self(testdir, cmd_opts):
963+
test_file = """
964+
import pytest
965+
import pytest_twisted
966+
967+
@pytest.fixture
968+
def foo():
969+
return 37
970+
971+
class TestClass:
972+
@pytest_twisted.ensureDeferred
973+
async def test_self_isinstance(self, foo):
974+
assert isinstance(self, TestClass)
975+
"""
976+
testdir.makepyfile(test_file)
977+
rr = testdir.run(*cmd_opts, timeout=timeout)
978+
assert_outcomes(rr, {"passed": 1})
979+
980+
981+
@skip_if_no_async_await()
982+
def test_ensuredeferred_method_with_fixture_gets_fixture(testdir, cmd_opts):
983+
test_file = """
984+
import pytest
985+
import pytest_twisted
986+
987+
@pytest.fixture
988+
def foo():
989+
return 37
990+
991+
class TestClass:
992+
@pytest_twisted.ensureDeferred
993+
async def test_self_isinstance(self, foo):
994+
assert foo == 37
995+
"""
996+
testdir.makepyfile(test_file)
997+
rr = testdir.run(*cmd_opts, timeout=timeout)
998+
assert_outcomes(rr, {"passed": 1})
999+
1000+
1001+
def test_import_pytest_twisted_in_conftest_py_not_a_problem(testdir, cmd_opts):
1002+
conftest_file = """
1003+
import pytest
1004+
import pytest_twisted
1005+
1006+
1007+
@pytest.hookimpl(tryfirst=True)
1008+
def pytest_configure(config):
1009+
pytest_twisted._use_asyncio_selector_if_required(config=config)
1010+
"""
1011+
testdir.makeconftest(conftest_file)
1012+
test_file = """
1013+
import pytest_twisted
1014+
1015+
def test_succeed():
1016+
pass
1017+
"""
1018+
testdir.makepyfile(test_file)
1019+
rr = testdir.run(*cmd_opts, timeout=timeout)
1020+
assert_outcomes(rr, {"passed": 1})

0 commit comments

Comments
 (0)