pytest-tap
pytest-tap is a reporting plugin for pytest that outputs Test Anything Protocol (TAP) data. TAP is a line-based test protocol for recording test data in a standard way. The current version is 3.5, and it regularly releases new versions to maintain compatibility with updated Python and pytest versions, typically on an irregular cadence.
Common errors
-
DeprecationWarning: '--tap-stream' is deprecated, use '--tap' instead.
cause Using the `--tap-stream` flag, which was deprecated in `pytest-tap` version 3.4.fixUpdate your pytest command to use `--tap` instead of `--tap-stream` for streaming TAP output. -
No TAP output is generated to stdout or in files, even though pytest runs successfully.
cause The `pytest-tap` plugin is installed, but no explicit TAP output mode was specified on the command line.fixAdd a TAP output flag to your pytest command, such as `pytest --tap`, `pytest --tap-files`, or `pytest --tap-combined`. -
ModuleNotFoundError: No module named 'pytest_tap'
cause The `pytest-tap` library is not installed in the active Python environment, or the environment where `pytest` is running cannot find it.fixRun `pip install pytest-tap` in your Python environment. Also, ensure your test files follow pytest's discovery conventions (e.g., `test_*.py` files, `test_*` functions).
Warnings
- deprecated The `--tap-stream` command-line flag was deprecated in version 3.4 in favor of the simpler `--tap` flag for streaming TAP output.
- gotcha The `pytest-tap` plugin is automatically activated upon installation, but it does not produce any output by default. You must explicitly enable a TAP output mode using one of the command-line flags.
- breaking Support for older Python versions is regularly dropped to align with Python's end-of-life schedule and pytest's support. For example, Python 3.8 support was dropped in `pytest-tap` v3.5, and Python 3.7/3.6 were dropped in v3.4.
Install
-
pip install pytest-tap
Quickstart
import pytest
# test_example.py
def test_passing_example():
assert 1 + 1 == 2
def test_failing_example():
assert 'hello'.upper() == 'WORLD'
def test_skipped_example():
pytest.skip("This test is intentionally skipped")
# To run: pytest --tap test_example.py
# This will output TAP data to stdout.