Skip to content

Commit

Permalink
keep test, warning
Browse files Browse the repository at this point in the history
  • Loading branch information
blueyed committed Jan 31, 2020
1 parent 7c4b8a0 commit 89abdb9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/_pytest/deprecated.py
Expand Up @@ -9,6 +9,7 @@
in case of warnings which need to format their messages.
"""
from _pytest.warning_types import PytestDeprecationWarning
from _pytest.warning_types import UnformattedWarning

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

NODE_USE_FROM_PARENT = UnformattedWarning(
PytestDeprecationWarning,
"direct construction of {name} has been deprecated, please use {name}.from_parent",
)

JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
"The 'junit_family' default value will change to 'xunit2' in pytest 6.0.\n"
"Add 'junit_family=xunit1' to your pytest.ini file to keep the current format "
Expand Down
1 change: 1 addition & 0 deletions src/_pytest/nodes.py
Expand Up @@ -19,6 +19,7 @@
from _pytest.compat import getfslineno
from _pytest.compat import TYPE_CHECKING
from _pytest.config import Config
from _pytest.deprecated import NODE_USE_FROM_PARENT
from _pytest.fixtures import FixtureDef
from _pytest.fixtures import FixtureLookupError
from _pytest.fixtures import FixtureLookupErrorRepr
Expand Down
17 changes: 17 additions & 0 deletions testing/deprecated_test.py
@@ -1,5 +1,8 @@
import inspect

import pytest
from _pytest import deprecated
from _pytest import nodes


@pytest.mark.filterwarnings("default")
Expand Down Expand Up @@ -73,3 +76,17 @@ def test_foo():
result.stdout.no_fnmatch_line(warning_msg)
else:
result.stdout.fnmatch_lines([warning_msg])


def test_node_direct_ctor_warning():
class MockConfig:
pass

ms = MockConfig()
with pytest.warns(
DeprecationWarning,
match="direct construction of .* has been deprecated, please use .*.from_parent",
) as w:
nodes.Node(name="test", config=ms, session=ms, nodeid="None")
assert w[0].lineno == inspect.currentframe().f_lineno - 1
assert w[0].filename == __file__

0 comments on commit 89abdb9

Please sign in to comment.