Terminal Reporting

Purpose

Terminal Reporting addresses the need for clear, concise, and informative feedback to users during and after test execution in the terminal. While the broader **Test Execution and Reporting** main topic covers running tests and generating reports, Terminal Reporting focuses specifically on how these results are presented live in the console and summarized at the end. It ensures that users can track progress, understand outcomes immediately, and quickly identify failures, warnings, and other test statuses without parsing complex report files.

This subtopic solves the problem of providing real-time visual feedback and a readable summary that balances verbosity and clarity, adapting to different user preferences and terminal capabilities.

Functionality

Terminal Reporting orchestrates the display of test progress and results via the terminal. Its key workflows and features include:

Example snippet showing how test status letters are printed during test execution:

def pytest_runtest_logreport(self, report: TestReport) -> None:
    # ...
    category, letter, word = self.config.hook.pytest_report_teststatus(report=rep, config=self.config)
    self._add_stats(category, [rep])
    if self.config.get_verbosity(Config.VERBOSITY_TEST_CASES) <= 0:
        self._tw.write(letter, **markup)
        # Progress info updated here if applicable

Integration

Terminal Reporting is tightly integrated with the overall **Test Execution and Reporting** parent topic as the user-facing presentation layer of test results. It builds upon the raw test outcome data generated by test runners and reports (`TestReport`, `CollectReport`) and transforms them into digestible terminal output.

It complements other subtopics as follows:

By managing all terminal output related to test progress and results, Terminal Reporting forms an essential bridge between the pytest core execution engine and the user’s immediate test feedback experience.

Diagram

flowchart TD
    Start[Test Session Start] --> Collect[Test Discovery & Collection]
    Collect --> DisplayCollect[Display Collection Progress]
    DisplayCollect --> RunTests[Test Execution Loop]
    RunTests --> LogReport[Receive Test Reports]
    LogReport --> UpdateProgress[Update Terminal Progress]
    LogReport --> ShowDetails[Display Detailed Info (if verbose)]
    RunTests --> Capture[Coordinate with Output Capture]
    RunTests --> HandleWarnings[Collect Warnings]
    RunTests --> HandleInterrupts[Handle Keyboard Interrupts]
    RunTests --> StoreStats[Accumulate Stats by Category]
    RunTests --> LoopContinue{More Tests?}
    LoopContinue -->|Yes| RunTests
    LoopContinue -->|No| SessionFinish[Test Session Finish]
    SessionFinish --> Summary[Display Final Summaries]
    Summary --> End[End of Test Run]

This flowchart visualizes the core process of terminal reporting during a pytest session: starting with test collection, running tests while updating progress and outputting status, handling warnings and interrupts, and finally producing a comprehensive summary.