Skip to content

Commit 28c28ec

Browse files
committed
Adjust test_blockon_in_pytest_deprecation()
1 parent 50fbce3 commit 28c28ec

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

testing/test_basic.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,37 +93,44 @@ def test_blockon_in_pytest():
9393
assert hasattr(pytest, 'blockon')
9494

9595

96-
def test_blockon_in_pytest_deprecation(testdir, cmd_opts):
96+
@pytest.mark.parametrize(
97+
'function, should_warn',
98+
(
99+
('pytest.blockon', True),
100+
('pytest_twisted.blockon', False),
101+
),
102+
)
103+
def test_blockon_in_pytest_deprecation(
104+
testdir,
105+
cmd_opts,
106+
function,
107+
should_warn,
108+
):
109+
import_path, _, _ = function.rpartition('.')
97110
test_file = """
98111
import warnings
99112
100113
from twisted.internet import reactor, defer
101114
import pytest
102-
import pytest_twisted
103-
104-
warnings.simplefilter("always")
115+
import {import_path}
105116
106-
@pytest.fixture(
107-
scope="module",
108-
params=[
109-
[pytest.blockon, 1],
110-
[pytest_twisted.blockon, 0],
111-
],
112-
)
117+
@pytest.fixture
113118
def foo(request):
114119
d = defer.Deferred()
115120
d.callback(None)
116-
with warnings.catch_warnings(record=True) as w:
117-
request.param[0](d)
118-
119-
return (w, request.param[1])
121+
{function}(d)
120122
121123
def test_succeed(foo):
122-
assert len(foo[0]) == foo[1]
123-
"""
124+
pass
125+
""".format(import_path=import_path, function=function)
124126
testdir.makepyfile(test_file)
125127
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
126-
assert_outcomes(rr, {"passed": 2})
128+
129+
expected_outcomes = {"passed": 1}
130+
if should_warn:
131+
expected_outcomes["warnings"] = 1
132+
133+
assert_outcomes(rr, expected_outcomes)
127134

128135

129136
def test_fail_later(testdir, cmd_opts):

0 commit comments

Comments
 (0)