A plugin that transforms the pytest output into a result similar to the RSpec. It enables the use of docstrings to display results and also enables the use of the prefixes "describe", "with" and "it".
Project description
pytest-pyspec
The pytest-pyspec plugin transforms pytest output into a beautiful, readable format similar to RSpec. It provides semantic meaning to your tests by organizing them into descriptive hierarchies.
Features
- Semantic Output: Transform pytest's default output into readable, hierarchical descriptions
- Multiple Prefixes: Support for
describe/test(objects),with/without/when(contexts), andit/test(tests) - Docstring Support: Override test descriptions using docstrings
- Consolidated Output: Smart grouping that avoids repeating parent headers
- Natural Language: Automatic lowercase formatting of common words (the, is, are, etc.)
Quick Start
Installation
pip install pytest pytest-pyspec
Running
pytest --pyspec
Examples
Car Scenario
A minimal car example with properties and behaviors:
class DescribeCar:
def test_has_engine(self):
assert True
class WithFullTank:
def test_drive_long_distance(self):
assert True
class WithoutFuel:
def test_cannot_start_engine(self):
assert True
class WhenTheEngineIsRunning:
def test_consumes_fuel(self):
assert True
With pytest-pyspec, this produces:
a Car
✓ has engine
with Full Tank
✓ drive long distance
without Fuel
✓ cannot start engine
when the Engine is Running
✓ consumes fuel
Available Prefixes
pytest-pyspec supports three types of prefixes to create semantic test hierarchies:
1. Object Classes (use describe or test)
Define what you're testing:
class DescribeCar: # or class TestCar:
def test_has_four_wheels(self):
assert True
Output:
a Car
✓ has four wheels
2. Context Classes (use with, without, or when)
Define the context or state:
class DescribeCar:
class WithFullTank:
def test_can_drive_long_distances(self):
assert True
class WithoutFuel:
def test_cannot_start_engine(self):
assert True
class WhenTheEngineIsRunning:
def test_consumes_fuel(self):
assert True
Output:
a Car
with Full Tank
✓ can drive long distances
without Fuel
✓ cannot start engine
when the Engine is Running
✓ consumes fuel
3. Test Functions (use it_ or test_)
Define the expected behavior:
class DescribeCar:
def it_has_four_wheels(self):
assert True
def test_has_engine(self):
assert True
Output:
a Car
✓ has four wheels
✓ has engine
Using Docstrings
Override automatic naming with custom descriptions:
class TestCar:
"""sports car"""
def test_top_speed(self):
"""reaches 200 mph"""
assert True
class WhenTheNitroIsActivated:
"""when nitro boost is activated"""
def test_acceleration(self):
"""accelerates rapidly"""
assert True
Output:
a sports car
✓ reaches 200 mph
when nitro boost is activated
✓ accelerates rapidly
Configuration
The plugin is automatically enabled when you use the --pyspec flag. No additional configuration is required.
For more information, see the documentation.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_pyspec-1.0.0.tar.gz.
File metadata
- Download URL: pytest_pyspec-1.0.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b56ff3cd1334f964023eb54213014a62d2106c7090709998e05f1bd0e708357d
|
|
| MD5 |
5853913d73f5847648c628be697ea61e
|
|
| BLAKE2b-256 |
910e35fce4543b6c53b3c565bc5ae254e34f087efe39d43c0ee48f303f9f0b8c
|
File details
Details for the file pytest_pyspec-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_pyspec-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83bd53c1031622b60f29691365e5b3f76ccdf0ab5d0c343ba866f30b132dd744
|
|
| MD5 |
af3b65f5586d6061c3989b9ab824dd25
|
|
| BLAKE2b-256 |
31bce7d6cc79bd452b02471b91416573d08e50e5414c5ceecefdc1e816076b6b
|