test_nodes.py

Overview

`test_nodes.py` is a test suite file for the `_pytest.nodes` module within the pytest testing framework. This file primarily focuses on verifying the correct behavior and enforcement of usage patterns related to pytest's internal `Node` class and its subclasses (`Item`, `Collector`, etc.). The tests cover:

The file uses `pytest` as the testing framework and interacts heavily with the internal pytest APIs and classes.


Detailed Explanation of Functions

test_node_from_parent_disallowed_arguments()


test_node_direct_construction_deprecated()


test_subclassing_both_item_and_collector_deprecated(request, tmp_path: Path)


test_node_warn_is_no_longer_only_pytest_warnings(pytester: Pytester, warn_type: type[Warning], msg: str)


test_node_warning_enforces_warning_types(pytester: Pytester)


test__check_initialpaths_for_relpath()


test_failure_with_changed_cwd(pytester: Pytester)


Important Implementation Details


Interactions with Other Parts of the System


Visual Diagram of Class and Function Relationships

flowchart TD
    A[test_node_from_parent_disallowed_arguments]
    B[test_node_direct_construction_deprecated]
    C[test_subclassing_both_item_and_collector_deprecated]
    D[test_node_warn_is_no_longer_only_pytest_warnings]
    E[test_node_warning_enforces_warning_types]
    F[test__check_initialpaths_for_relpath]
    G[test_failure_with_changed_cwd]

    subgraph "Test Suite: test_nodes.py"
        A
        B
        C
        D
        E
        F
        G
    end

    A -->|calls| nodes.Node.from_parent
    B -->|calls| nodes.Node.__init__
    C -->|defines subclass| SoWrong[nodes.Item, nodes.File]
    C -->|calls| SoWrong.from_parent
    D -->|calls| pytester.getitems
    D -->|calls| Node.warn
    E -->|calls| Node.warn
    F -->|tests| nodes._check_initialpaths_for_relpath
    G -->|creates test file| pytester.makepyfile
    G -->|runs pytest| pytester.runpytest

    subgraph "Dependencies"
        nodes._pytest_nodes["_pytest.nodes"]
        pytester._pytest_pytester["_pytest.pytester"]
        outcomes._pytest_outcomes["_pytest.outcomes"]
        warning_types._pytest_warning_types["_pytest.warning_types"]
    end

    A --> nodes._pytest_nodes
    B --> nodes._pytest_nodes
    C --> nodes._pytest_nodes
    D --> pytester._pytest_pytester
    E --> pytester._pytest_pytester
    F --> nodes._pytest_nodes
    G --> pytester._pytest_pytester

Summary

`test_nodes.py` is a focused pytest test module that ensures the robustness, correctness, and expected usage of pytest's core `Node` class and related internals. It enforces new construction patterns, validates warning handling, detects deprecated subclassing patterns, and confirms path correctness in failure reporting. This test suite plays a vital role in maintaining the integrity of pytest's node and collection APIs as the framework evolves.