Skip to content

Commit 50fbce3

Browse files
committed
Adjust test_inline_callbacks_in_pytest_deprecation()
1 parent 8b31067 commit 50fbce3

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

testing/test_basic.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,36 @@ def test_inline_callbacks_in_pytest():
5757
assert hasattr(pytest, 'inlineCallbacks')
5858

5959

60-
def test_inline_callbacks_in_pytest_deprecation(testdir, cmd_opts):
60+
@pytest.mark.parametrize(
61+
'decorator, should_warn',
62+
(
63+
('pytest.inlineCallbacks', True),
64+
('pytest_twisted.inlineCallbacks', False),
65+
),
66+
)
67+
def test_inline_callbacks_in_pytest_deprecation(
68+
testdir,
69+
cmd_opts,
70+
decorator,
71+
should_warn,
72+
):
73+
import_path, _, _ = decorator.rpartition('.')
6174
test_file = """
62-
import warnings
63-
64-
from twisted.internet import reactor, defer
65-
import pytest
66-
import pytest_twisted
67-
68-
warnings.simplefilter("always")
75+
import {import_path}
6976
70-
@pytest.mark.parametrize(
71-
argnames='decorator, warning_count',
72-
argvalues=[
73-
[pytest.inlineCallbacks, 1],
74-
[pytest_twisted.inlineCallbacks, 0],
75-
],
76-
)
77-
def test_inline_callbacks_in_pytest_deprecated(decorator, warning_count):
78-
with warnings.catch_warnings(record=True) as w:
79-
@decorator
80-
def f():
81-
yield 42
82-
83-
assert len(w) == warning_count
84-
"""
77+
def test_deprecation():
78+
@{decorator}
79+
def f():
80+
yield 42
81+
""".format(import_path=import_path, decorator=decorator)
8582
testdir.makepyfile(test_file)
8683
rr = testdir.run(sys.executable, "-m", "pytest", "-v", *cmd_opts)
87-
assert_outcomes(rr, {"passed": 2})
84+
85+
expected_outcomes = {"passed": 1}
86+
if should_warn:
87+
expected_outcomes["warnings"] = 1
88+
89+
assert_outcomes(rr, expected_outcomes)
8890

8991

9092
def test_blockon_in_pytest():

0 commit comments

Comments
 (0)