From 59d314de3d6aff2f8af2b2ea1e96694900efe20e Mon Sep 17 00:00:00 2001 From: Emmanuel Arias Date: Tue, 31 Aug 2021 09:12:11 -0300 Subject: [PATCH] Show fullname on direct Node construction warning This commit add the fullname on the Node construction warning. Also add a test for this case. --- src/_pytest/nodes.py | 2 +- testing/test_nodes.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index e695f89bb..d3f0ddceb 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -123,7 +123,7 @@ class NodeMeta(type): "See " "https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent" " for more details." - ).format(name=self.__name__) + ).format(name=f"{self.__module__}.{self.__name__}") fail(msg, pytrace=False) def _create(self, *k, **kw): diff --git a/testing/test_nodes.py b/testing/test_nodes.py index 52cd0173c..57a942c25 100644 --- a/testing/test_nodes.py +++ b/testing/test_nodes.py @@ -6,6 +6,7 @@ from typing import Type import pytest from _pytest import nodes from _pytest.compat import legacy_path +from _pytest.outcomes import OutcomeException from _pytest.pytester import Pytester from _pytest.warning_types import PytestWarning @@ -40,6 +41,19 @@ def test_node_from_parent_disallowed_arguments() -> None: nodes.Node.from_parent(None, config=None) # type: ignore[arg-type] +def test_node_direct_construction_deprecated() -> None: + with pytest.raises( + OutcomeException, + match=( + "Direct construction of _pytest.nodes.Node has been deprecated, please " + "use _pytest.nodes.Node.from_parent.\nSee " + "https://docs.pytest.org/en/stable/deprecations.html#node-construction-changed-to-node-from-parent" + " for more details." + ), + ): + nodes.Node(None, session=None) # type: ignore[arg-type] + + def test_subclassing_both_item_and_collector_deprecated( request, tmp_path: Path ) -> None: