Skip to content

Commit f4ba7b1

Browse files
committed
add tests for ensureDeferred decorated methods with a fixture
1 parent 6125aab commit f4ba7b1

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

testing/test_basic.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,3 +948,43 @@ def test_self_isinstance(self, foo):
948948
testdir.makepyfile(test_file)
949949
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
950950
assert_outcomes(rr, {"passed": 1})
951+
952+
953+
@skip_if_no_async_await()
954+
def test_ensuredeferred_method_with_fixture_gets_self(testdir, cmd_opts):
955+
test_file = """
956+
import pytest
957+
import pytest_twisted
958+
959+
@pytest.fixture
960+
def foo():
961+
return 37
962+
963+
class TestClass:
964+
@pytest_twisted.ensureDeferred
965+
async def test_self_isinstance(self, foo):
966+
assert isinstance(self, TestClass)
967+
"""
968+
testdir.makepyfile(test_file)
969+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
970+
assert_outcomes(rr, {"passed": 1})
971+
972+
973+
@skip_if_no_async_await()
974+
def test_ensuredeferred_method_with_fixture_gets_fixture(testdir, cmd_opts):
975+
test_file = """
976+
import pytest
977+
import pytest_twisted
978+
979+
@pytest.fixture
980+
def foo():
981+
return 37
982+
983+
class TestClass:
984+
@pytest_twisted.ensureDeferred
985+
async def test_self_isinstance(self, foo):
986+
assert foo == 37
987+
"""
988+
testdir.makepyfile(test_file)
989+
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
990+
assert_outcomes(rr, {"passed": 1})

0 commit comments

Comments
 (0)