Skip to content

Commit 89abdb9

Browse files
committed
keep test, warning
1 parent 7c4b8a0 commit 89abdb9

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/_pytest/deprecated.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
in case of warnings which need to format their messages.
1010
"""
1111
from _pytest.warning_types import PytestDeprecationWarning
12+
from _pytest.warning_types import UnformattedWarning
1213

1314
# set of plugins which have been integrated into the core; we use this list to ignore
1415
# them during registration to avoid conflicts
@@ -35,6 +36,11 @@
3536
"as a keyword argument instead."
3637
)
3738

39+
NODE_USE_FROM_PARENT = UnformattedWarning(
40+
PytestDeprecationWarning,
41+
"direct construction of {name} has been deprecated, please use {name}.from_parent",
42+
)
43+
3844
JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
3945
"The 'junit_family' default value will change to 'xunit2' in pytest 6.0.\n"
4046
"Add 'junit_family=xunit1' to your pytest.ini file to keep the current format "

src/_pytest/nodes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from _pytest.compat import getfslineno
2020
from _pytest.compat import TYPE_CHECKING
2121
from _pytest.config import Config
22+
from _pytest.deprecated import NODE_USE_FROM_PARENT
2223
from _pytest.fixtures import FixtureDef
2324
from _pytest.fixtures import FixtureLookupError
2425
from _pytest.fixtures import FixtureLookupErrorRepr

testing/deprecated_test.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
import inspect
2+
13
import pytest
24
from _pytest import deprecated
5+
from _pytest import nodes
36

47

58
@pytest.mark.filterwarnings("default")
@@ -73,3 +76,17 @@ def test_foo():
7376
result.stdout.no_fnmatch_line(warning_msg)
7477
else:
7578
result.stdout.fnmatch_lines([warning_msg])
79+
80+
81+
def test_node_direct_ctor_warning():
82+
class MockConfig:
83+
pass
84+
85+
ms = MockConfig()
86+
with pytest.warns(
87+
DeprecationWarning,
88+
match="direct construction of .* has been deprecated, please use .*.from_parent",
89+
) as w:
90+
nodes.Node(name="test", config=ms, session=ms, nodeid="None")
91+
assert w[0].lineno == inspect.currentframe().f_lineno - 1
92+
assert w[0].filename == __file__

0 commit comments

Comments
 (0)