Skip to main content

A pytest plugin that provides elegant, beautiful test output

Project description

pytest-elegant

A pytest plugin that provides elegant, beautiful test output inspired by Pest PHP's aesthetic.

Features

  • Clean, minimal output with ✓/✗ symbols instead of dots/F/E
  • Colored results - green for passing tests, red for failures, yellow for skipped
  • File grouping - Tests organized by file with PASS/FAIL headers
  • Duration display - See how long each test takes (e.g., 0.12s)
  • Immediate failure details - See what went wrong right away with code context
  • Zero configuration - Just install and run pytest as usual
  • Standard pytest syntax - Keep your existing def test_* functions

Installation

Using uv (recommended)

uv add --dev pytest-elegant

Using pip

pip install pytest-elegant

Usage

Once installed, pytest-elegant automatically transforms your pytest output. Just run:

pytest

That's it! No configuration needed.

Successful Example Output

Before (standard pytest):

After (with pytest-elegant):

Failure Example Output

Before (standard pytest):

After (with pytest-elegant):

After (with pytest-elegant with verbose mode):

Configuration

pytest-elegant works out of the box, but you can customize it via pytest.ini or pyproject.toml.

pyproject.toml

[tool.pytest.ini_options]
elegant_show_context = true      # Show code context in failure output (default: true)
elegant_group_by_file = true     # Group test results by file (default: true)
elegant_show_duration = true     # Show test duration for each test (default: true)

pytest.ini

[pytest]
elegant_show_context = true
elegant_group_by_file = true
elegant_show_duration = true

Disabling pytest-elegant

If you need to temporarily disable pytest-elegant and see standard pytest output:

pytest --no-elegant

Verbose Mode

pytest-elegant respects pytest's verbosity flags:

pytest -v      # More details (full file paths, more context)
pytest -vv     # Maximum details (full stack traces)

Advanced Features

Parametrized Tests

pytest-elegant beautifully formats parametrized tests, showing each parameter set:

  ✓ test_math[1-2-3] 0.01s
  ✓ test_math[4-5-9] 0.01s
  ⨯ test_math[10-20-50] 0.02s

Test Classes

Test classes are handled with proper nesting:

  PASS  tests/test_user.py
  ✓ TestUser::test_creation 0.02s
  ✓ TestUser::test_validation 0.01s

Skipped and Expected Failures

Different test outcomes have distinct symbols:

  • - Passed (green)
  • - Failed (red)
  • - - Skipped (yellow)
  • x - Expected failure (yellow)
  • X - Unexpected pass (yellow)

Unicode Support

If your terminal doesn't support ✓/✗ symbols, pytest-elegant automatically falls back to ASCII alternatives (PASS/FAIL).

Compatibility

  • Python: 3.14+
  • pytest: 7.0.0+
  • Terminal: Any terminal with ANSI color support
  • Parallel testing: Compatible with pytest-xdist

How It Works

pytest-elegant is a pytest plugin that:

  1. Registers via the pytest11 entry point
  2. Replaces pytest's default TerminalReporter with a custom one
  3. Customizes output formatting hooks to provide elegant, minimal output
  4. Uses pytest's built-in color support (no extra dependencies)

Development

Running Tests

# Run all tests
pytest

# Run specific test file
pytest tests/test_reporter.py

Type Checking

mypy src/pytest_elegant

Linting

ruff check src/pytest_elegant

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new features
  4. Ensure all tests pass
  5. Submit a pull request

Author

Yann Rabiller (@einenlum) | blog | From PHP to Python

License

MIT License - see LICENSE file for details

Credits

Heavily inspired by Pest PHP by Nuno Maduro and contributors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_elegant-0.1.6.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_elegant-0.1.6-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file pytest_elegant-0.1.6.tar.gz.

File metadata

  • Download URL: pytest_elegant-0.1.6.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for pytest_elegant-0.1.6.tar.gz
Algorithm Hash digest
SHA256 f5346dc340e65dd6ba0d6a0b8226cbe3c24b8e5bf243d0da5255b740bf5fa643
MD5 6a093353606383b21ed1584b25ebf103
BLAKE2b-256 d4343a2caeabceb5e13c268f6c32e27496b21849fcb7daa4a59a4582af0d97b8

See more details on using hashes here.

File details

Details for the file pytest_elegant-0.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_elegant-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 041295c039a8bc8d1ac03a45d76bd6e716e563025d2debdb3a7356fc6d9a0127
MD5 89c7bdab5e09ff4ee1361ec8f37a9581
BLAKE2b-256 32f6611f7e08c1a69800294af7299c77c2d96655bb553ba742b93a8973752755

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page