integration.py

Overview

The `integration.py` file is a test suite primarily focused on verifying the behavior and integration of mocking and patching features within the `pytest` testing framework. It contains a collection of test cases that ensure compatibility and correct functionality when using various mocking utilities such as `unittest.mock`, the third-party `mock` package, and `pytest` fixtures.

This file tests complex scenarios involving wrapped functions, mock decorators, interaction of mocks with fixtures, parameterization of tests, and correct behavior of test collection and rerun mechanisms. It also verifies that pytest's internal utilities for function inspection unwrap decorated or patched functions properly.

The tests target the integration points of pytest's test collection, execution, and mocking support, helping maintain robust and predictable behavior when users combine these features in practical test suites.


Classes, Functions, and Methods

Functions

test_wrapped_getfslineno() -> None


Class: TestMockDecoration

A collection of tests focused on verifying that pytest interacts correctly with mock decorators and patched functions.

Methods:


Class: TestReRunTests

Tests related to pytest's rerun functionality.


Function: test_pytestconfig_is_session_scoped() -> None


Class: TestNoselikeTestAttribute

Tests the behavior of the `__test__` attribute that controls whether modules, classes, or functions are considered test items by pytest.


Class: TestParameterize

Tests related to pytest's parameterization features.


Function: test_function_instance(pytester: Pytester) -> None


Important Implementation Details and Algorithms


Interaction with Other System Components


Usage Example

The file itself is not intended to be imported as a module but run as a pytest test suite to verify pytest's integration with mocks and decorators. To execute the tests:

pytest integration.py

Diagram: Class Diagram of Test Classes and Methods

classDiagram
    class TestMockDecoration {
        +test_wrapped_getfuncargnames()
        +test_getfuncargnames_patching()
        +test_unittest_mock(pytester)
        +test_unittest_mock_and_fixture(pytester)
        +test_unittest_mock_and_pypi_mock(pytester)
        +test_mock_sentinel_check_against_numpy_like(pytester)
        +test_mock(pytester)
        +test_mock_sorting(pytester)
        +test_mock_double_patch_issue473(pytester)
    }

    class TestReRunTests {
        +test_rerun(pytester)
    }

    class TestNoselikeTestAttribute {
        +test_module_with_global_test(pytester)
        +test_class_and_method(pytester)
        +test_unittest_class(pytester)
        +test_class_with_nasty_getattr(pytester)
    }

    class TestParameterize {
        +test_idfn_marker(pytester)
        +test_idfn_fixture(pytester)
        +test_param_rejects_usefixtures(pytester)
    }

    TestMockDecoration <|-- integration.py
    TestReRunTests <|-- integration.py
    TestNoselikeTestAttribute <|-- integration.py
    TestParameterize <|-- integration.py

Summary

`integration.py` is a comprehensive test suite for pytest's integration with mocking frameworks and test parameterization. It ensures that pytest can correctly unwrap decorated functions, handle mock patches, respect test-disabling attributes, and maintain fixture and test execution correctness across reruns and complex decoration scenarios. This file acts as a critical safeguard for pytest's interoperability with mocking utilities and advanced test features.