tmp_path

A built-in pytest fixture that gives each test its own fresh temporary directory as a pathlib.Path.

In more detail

Because the directory is unique to one test, nothing another test wrote can make it pass by accident. pytest creates it under the system temporary directory and cleans up old ones automatically, keeping the last few runs for inspection.

Example

def test_report_is_written(tmp_path):
    path = write_report(tmp_path, "daily.txt", "ready")

Related terms

Taught in

References