pytest-print

1.2.2 · active · verified Fri Apr 17

pytest-print is a pytest plugin that provides fixtures like `printer` and `pprint` for writing messages directly to the pytest runner terminal, bypassing pytest's default output capture. It is actively maintained, with version 1.2.2 requiring Python >=3.10, and sees regular patch and minor releases.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates the use of the `printer` and `pprint` fixtures to output messages directly to the terminal during a pytest run, bypassing standard capture. Note the recommendation to use `-s` for `print()` output to appear.

import pytest

def test_printer_fixture(printer):
    # The 'printer' fixture writes directly to the terminal, bypassing pytest's stdout capture.
    printer("Hello from pytest-print! This message should always appear.")
    print("This is a standard print. It will be captured unless pytest is run with -s.")

def test_pprint_fixture(pprint):
    data = {'name': 'Alice', 'age': 30, 'cities': ['New York', 'London']}
    pprint(data)
    pprint([1, 2, 3, {'a': 'b', 'c': 'd'}])

# To run this test:
# 1. Save as a Python file (e.g., test_my_app.py)
# 2. Run from your terminal in the same directory: pytest -v -s test_my_app.py

view raw JSON →