{"id":10147,"library":"pytest-print","title":"pytest-print","description":"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.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/pytest-dev/pytest-print","tags":["pytest","testing","cli","debug","fixtures"],"install":[{"cmd":"pip install pytest-print","lang":"bash","label":"Install pytest-print"}],"dependencies":[{"reason":"Core test framework dependency; pytest-print extends pytest functionality by providing fixtures.","package":"pytest","optional":false}],"imports":[{"note":"The 'printer' fixture is automatically discovered by pytest and injected into test functions; no explicit import statement is typically needed in test files.","wrong":"from pytest_print import printer","symbol":"printer","correct":"def test_example(printer):"},{"note":"The 'pprint' fixture is automatically discovered by pytest and injected into test functions for pretty-printing data.","wrong":"from pytest_print import pprint","symbol":"pprint","correct":"def test_example(pprint):"},{"note":"The 'printer_factory' fixture provides a callable to create custom printer instances.","wrong":"from pytest_print import printer_factory","symbol":"printer_factory","correct":"def test_example(printer_factory):"}],"quickstart":{"code":"import pytest\n\ndef test_printer_fixture(printer):\n    # The 'printer' fixture writes directly to the terminal, bypassing pytest's stdout capture.\n    printer(\"Hello from pytest-print! This message should always appear.\")\n    print(\"This is a standard print. It will be captured unless pytest is run with -s.\")\n\ndef test_pprint_fixture(pprint):\n    data = {'name': 'Alice', 'age': 30, 'cities': ['New York', 'London']}\n    pprint(data)\n    pprint([1, 2, 3, {'a': 'b', 'c': 'd'}])\n\n# To run this test:\n# 1. Save as a Python file (e.g., test_my_app.py)\n# 2. Run from your terminal in the same directory: pytest -v -s test_my_app.py","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python environment to 3.10 or newer, or pin pytest-print to a version less than 1.2.0 if you must use older Python versions (e.g., `pytest-print<1.2.0` for Python 3.9).","message":"pytest-print v1.2.0 dropped support for Python 3.8 and 3.9. Subsequent versions, including 1.2.2, require Python >=3.10.","severity":"breaking","affected_versions":">=1.2.0"},{"fix":"Use `printer()` or `pprint()` when you specifically need output to appear immediately on the terminal regardless of pytest's capture settings. For regular `print()` statements, either run pytest with `-s` (or `--capture=no`), or expect them to be captured and displayed only on test failure or with specific `--show-capture` options.","message":"The `printer` and `pprint` fixtures bypass pytest's standard stdout/stderr capture mechanisms to ensure output is always visible in the terminal. This can be confusing if you expect all `print()` statements to behave similarly.","severity":"gotcha","affected_versions":"*"},{"fix":"Ensure your testing environment is on Python 3.10+ and that any custom integrations or plugins are tested against `pytest-print` 1.2.1 or newer. Consult `pytest`'s public API for best practices.","message":"Version 1.2.1 included internal modernizations for Python 3.10+ and public pytest APIs. While not typically affecting end-user tests directly, this may subtly break compatibility for advanced users or other plugins relying on specific internal behaviors of `pytest-print` prior to this version.","severity":"breaking","affected_versions":">=1.2.1"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure `pytest-print` is installed via `pip install pytest-print` in the same environment where `pytest` is being run. Verify `pytest` itself is correctly installed and accessible.","cause":"The `pytest-print` plugin is not installed in the active Python environment or pytest is not discovering plugins correctly.","error":"fixture 'printer' not found"},{"fix":"If you want standard `print()` statements to appear during test execution, run `pytest` with the `-s` flag (e.g., `pytest -s`). Alternatively, use the `printer` fixture for all direct terminal output you wish to always see.","cause":"pytest captures standard output and error by default. The `printer` and `pprint` fixtures explicitly bypass this capture, which is their intended behavior.","error":"My `print()` statements aren't showing up during tests, but `printer()` output does."}]}