test_reporting.py


Overview

The [test_reporting.py](/projects/286/66996) file contains a comprehensive suite of automated tests designed to verify and validate logging and reporting functionalities within the pytest framework. These tests primarily cover how pytest handles capturing, displaying, and storing log messages generated during test execution, including standard output/error, Python logging calls, and live logging output.

Key testing scenarios include:

The file leverages the `pytester` testing utility from pytest for creating temporary test files, running pytest with various configurations, and asserting on the outputs.


Detailed Explanation of Key Functions

Each function in this file is a test case for a specific logging/reporting feature. They follow the pytest convention for test functions and use fixtures like `pytester` and `request` for test environment setup.


test_nothing_logged(pytester: Pytester) -> None


test_messages_logged(pytester: Pytester) -> None


test_root_logger_affected(pytester: Pytester) -> None


test_log_cli_level_log_level_interaction(pytester: Pytester) -> None


test_setup_logging(pytester: Pytester) -> None


test_teardown_logging(pytester: Pytester) -> None


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


test_log_cli_default_level(pytester: Pytester) -> None


test_log_cli_default_level_multiple_tests(pytester: Pytester, request: FixtureRequest) -> None


test_live_logs_unknown_sections(pytester: Pytester, request: FixtureRequest) -> None


test_log_cli_level(pytester: Pytester) -> None


test_log_file_cli(pytester: Pytester) -> None


test_log_file_mode_cli(pytester: Pytester) -> None


test_log_file_mode_cli_invalid(pytester: Pytester) -> None


test_log_file_unicode(pytester: Pytester) -> None


test_live_logging_suspends_capture(has_capture_manager: bool, request: FixtureRequest) -> None


test_collection_live_logging(pytester: Pytester) -> None


test_log_in_hooks(pytester: Pytester) -> None


test_log_set_path(pytester: Pytester) -> None


test_colored_captured_log(pytester: Pytester) -> None


test_logging_emit_error(pytester: Pytester) -> None


test_logging_emit_error_supressed(pytester: Pytester) -> None


test_disable_loggers(pytester: Pytester) -> None


test_disable_loggers_does_not_propagate(pytester: Pytester) -> None


test_log_disabling_works_with_log_cli(pytester: Pytester) -> None


test_without_date_format_log(pytester: Pytester) -> None


test_date_format_log(pytester: Pytester) -> None


test_date_format_percentf_log(pytester: Pytester) -> None


test_date_format_percentf_tz_log(pytester: Pytester) -> None


Other Tests

The file also contains multiple tests for:


Implementation Details and Algorithms


Interaction with Other System Components


Visual Diagram

flowchart TD
    A[pytester Fixture] -->|Creates test files and ini| B[Dynamic Test Scripts]
    B --> C[Run pytest subprocess]
    C --> D{Logging Features Tested}
    D -->|Capture stdout/stderr| E[Capture Tests]
    D -->|Capture logging calls| F[Logging Capture Tests]
    D -->|CLI options interaction| G[CLI Level Tests]
    D -->|Live logging output| H[Live Logging Tests]
    D -->|Log file handling| I[Log File Tests]
    D -->|Logging in hooks| J[Hook Integration Tests]
    D -->|Logger disabling| K[Disable Logger Tests]
    D -->|Error propagation| L[Logging Error Tests]
    E & F & G & H & I & J & K & L --> M[Assertions on output & file contents]

Summary

[test_reporting.py](/projects/286/66996) is a critical test suite validating pytest's robust logging and reporting capabilities. It ensures that users see correct, well-formatted, and configurable log output during test runs, whether on terminal or in log files. The tests cover a wide range of scenarios from simple stdout capture to complex live logging with dynamic configurations, making this file essential for maintaining the quality and reliability of pytest's logging features.