test_faulthandler.py


Overview

The [test_faulthandler.py](/projects/286/67400) file contains a suite of automated tests verifying the integration and functionality of the `faulthandler` support within the pytest testing framework. `faulthandler` is a Python module that helps diagnose crashes by dumping Python tracebacks explicitly on faults like segmentation faults, abort signals, or timeouts.

This test file ensures that:

These tests are primarily functional and integration tests, using the pytest framework's own testing utilities (`pytester`) to run subprocesses and verify outputs.


Detailed Explanations

Imports


Functions

All test functions use the `pytester` fixture or `pytest` directly to create temporary test files and run pytest subprocesses to verify `faulthandler` behavior.


test_enabled(pytester: Pytester) -> None


setup_crashing_test(pytester: Pytester) -> None


test_crash_during_shutdown_captured(pytester: Pytester) -> None


test_crash_during_shutdown_not_captured(pytester: Pytester) -> None


test_disabled(pytester: Pytester) -> None


test_timeout(pytester: Pytester, enabled: bool) -> None


test_cancel_timeout_on_hook(monkeypatch, hook_name) -> None


test_already_initialized_crash(pytester: Pytester) -> None


test_get_stderr_fileno_invalid_fd() -> None


Important Implementation Details


Interactions with Other Parts of the System


Visual Diagram

classDiagram
    class test_faulthandler {
        +test_enabled(pytester)
        +setup_crashing_test(pytester)
        +test_crash_during_shutdown_captured(pytester)
        +test_crash_during_shutdown_not_captured(pytester)
        +test_disabled(pytester)
        +test_timeout(pytester, enabled)
        +test_cancel_timeout_on_hook(monkeypatch, hook_name)
        +test_already_initialized_crash(pytester)
        +test_get_stderr_fileno_invalid_fd()
    }

    test_faulthandler ..> Pytester : uses
    test_faulthandler ..> pytest : uses
    test_faulthandler ..> faulthandler : tests integration
    test_faulthandler ..> _pytest.faulthandler : accesses hooks & functions

Summary

The [test_faulthandler.py](/projects/286/67400) file is a critical integration test suite that validates the pytest faulthandler plugin's functionality. It tests various scenarios involving fault detection, crash tracebacks, plugin enabling/disabling, timeouts, and compatibility with interpreter shutdown and debugging hooks. The tests leverage pytest's own testing infrastructure to simulate real-world usage and edge cases, ensuring robust and reliable fault diagnostics during test execution.