Merge pull request #9066 from eamanu/fix-8994

This commit is contained in:
Bruno Oliveira 2021-10-05 16:52:08 -03:00 committed by GitHub
commit 9546fb713a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -0,0 +1,2 @@
Included the module of the class in the error message about direct
node construction (without using ``from_parent``).

View File

@ -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):

View File

@ -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: