pytest-spec: Specification-style Test Output

6.0.0 · active · verified Fri Apr 17

pytest-spec is a pytest plugin that transforms the standard test execution output into a clear, human-readable specification format, similar to RSpec or Mocha. It uses test names and docstrings to generate descriptive sentences about test behavior. The current version is 6.0.0, and it follows a release cadence tied to pytest and Python major version updates.

Common errors

Warnings

Install

Quickstart

Create a test file (e.g., `test_example.py`) and simply run `pytest` from your terminal after installation. pytest-spec automatically modifies the output.

# test_example.py
import pytest

def test_feature_login_successful():
    """When valid credentials are provided, it should allow a user to log in successfully."""
    assert True

def test_feature_login_failed():
    """When invalid credentials are provided, it should deny access and show an error."""
    assert False

@pytest.mark.parametrize("input, expected", [("hello", "HELLO"), ("world", "WORLD")])
def test_string_uppercase_conversion(input, expected):
    """It should correctly convert a given string to uppercase."""
    assert input.upper() == expected

# To run these tests with pytest-spec, simply navigate to the directory
# containing `test_example.py` in your terminal and run:
# pytest

view raw JSON →