builtin

Overview

The [builtin](/projects/286/67223) file serves as a centralized documentation hub for **pytest's built-in API and fixtures**. Rather than implementing functionality directly, it primarily provides detailed descriptions of the most commonly used builtin fixtures and APIs offered by pytest, acting as a comprehensive reference guide for users writing tests with pytest.

This file organizes the documentation for pytest's builtin fixtures, explaining their purposes, usage patterns, parameters (where applicable), and examples. It also points users to more detailed API references and specific pytest subsystems such as plugins, marks, and fixtures.

The documentation covers fixtures related to:

Since this file does not contain executable code or class/function definitions, it acts as an extended help page or builtin reference, guiding users to understand and effectively use pytest's builtin fixtures.


Detailed Descriptions of Fixtures and APIs

Below is an elaboration of the documented pytest builtin fixtures and APIs described in this file.

1. cache

2. capsys

3. capteesys

4. capsysbinary

5. capfd

6. capfdbinary

7. doctest_namespace

8. pytestconfig

9. record_property

10. record_xml_attribute

11. record_testsuite_property

12. tmpdir_factory

13. tmpdir

14. caplog

15. monkeypatch

16. recwarn

17. tmp_path_factory

18. tmp_path


Implementation Details & Algorithms


Interactions with Other System Components


Usage Examples Summary


Mermaid Diagram: pytest Builtin Fixtures Structure

classDiagram
    class cache {
        +get(key, default)
        +set(key, value)
    }

    class capsys {
        +readouterr() : (out:str, err:str)
    }

    class capteesys {
        +readouterr() : (out:str, err:str)
    }

    class capsysbinary {
        +readouterr() : (out:bytes, err:bytes)
    }

    class capfd {
        +readouterr() : (out:str, err:str)
    }

    class capfdbinary {
        +readouterr() : (out:bytes, err:bytes)
    }

    class doctest_namespace {
        <<fixture>>
        +dict injected into doctests
    }

    class pytestconfig {
        <<fixture>>
        +Config object access
    }

    class record_property {
        +call(name, value)
    }

    class record_xml_attribute {
        +call(name, value)
    }

    class record_testsuite_property {
        +call(name, value)
    }

    class tmpdir_factory {
        <<fixture>>
        +TempdirFactory instance
    }

    class tmpdir {
        <<fixture>>
        +legacy_path temp directory
    }

    class tmp_path_factory {
        <<fixture>>
        +TempPathFactory instance
    }

    class tmp_path {
        <<fixture>>
        +pathlib.Path temp directory
    }

    class caplog {
        +messages: list
        +text: str
        +records: list
        +record_tuples: list
        +clear()
    }

    class monkeypatch {
        +setattr(obj, name, value, raising)
        +delattr(obj, name, raising)
        +setitem(mapping, name, value)
        +delitem(obj, name, raising)
        +setenv(name, value, prepend)
        +delenv(name, raising)
        +syspath_prepend(path)
        +chdir(path)
        +context()
    }

    class recwarn {
        +WarningsRecorder instance
    }

    cache <|-- capsys
    capsys <|-- capteesys
    capsys <|-- capsysbinary
    capfd <|-- capfdbinary
    tmpdir_factory <|-- tmpdir
    tmp_path_factory <|-- tmp_path

Summary

The [builtin](/projects/286/67223) file is an essential pytest reference document describing builtin fixtures and APIs that facilitate common testing tasks such as output capturing, temporary file management, environment patching, logging, warnings capture, and test metadata recording. It acts as a starting point for pytest users to understand available builtin helpers and how to leverage them in their test suites. The file links to more detailed API references and plugin documentation, ensuring users can explore pytest's rich feature set effectively.

Because it is documentation only, it does not include executable code but comprehensively explains the interfaces provided by pytest core fixtures.