Skip to main content

Comprehensive test failure extraction and reporting library for pytest

Project description

FailExtract: Test Failure Analysis Library

Python 3.11+ PyPI version License: Apache 2.0

FailExtract is a lightweight test failure extraction and reporting library for pytest environments. It automatically captures detailed failure context including fixture information, source code, and exception details to improve debugging efficiency.

Key Features

  • ๐ŸŽฏ Simple Installation: Easy to get started with minimal dependencies
  • ๐Ÿ“Š Multiple Output Formats: JSON (built-in), XML, CSV, YAML, and Markdown
  • โšก Lightweight Core: Fast extraction with configurable output options
  • ๐ŸŽจ Command-Line Interface: Generate reports and analyze failures from CLI
  • ๐Ÿงต Thread-Safe: Works with concurrent test execution
  • โš™๏ธ Decorator Support: Simple @extract_on_failure decorator for any test
  • ๐Ÿ”ง Configurable: Flexible output configuration and formatting options

Installation Options

Installation

# Standard installation - includes all core formatters
pip install failextract

Includes: Failure extraction, JSON/XML/CSV/Markdown formatters, and CLI commands.

Optional Features

# Add YAML output support
pip install failextract[formatters]

# Enhanced configuration file support (pydantic)
pip install failextract[config]

# Rich CLI output formatting
pip install failextract[cli]

Development Installation

# All optional features for development
pip install failextract[development]

# Install with all features
pip install failextract[all]

Check Available Features

# See what features are installed
failextract features

# Get installation suggestions for missing features
failextract --help

Basic Usage

Transform any test function into a failure-capturing test with a simple decorator:

from failextract import extract_on_failure

@extract_on_failure
def test_user_registration():
    user = create_user("john@example.com")
    assert user.is_active == True, "User should be active after registration"

When this test fails, FailExtract automatically captures:

  • Complete fixture dependency chain
  • Source code context
  • Exception details with full traceback
  • Local variable states
  • Test execution metadata

Generate Reports (Core - Always Available)

from failextract import FailureExtractor, OutputConfig

# Extract failures and generate reports
extractor = FailureExtractor()

# Generate JSON report (always available)
json_config = OutputConfig("failures.json", format="json")
extractor.save_report(json_config)

Multiple Output Formats

# XML output (built-in)
xml_config = OutputConfig("failures.xml", format="xml")
extractor.save_report(xml_config)

# Markdown output (built-in)
md_config = OutputConfig("failures.md", format="markdown")
extractor.save_report(md_config)

# YAML output (requires formatters extra)
yaml_config = OutputConfig("failures.yaml", format="yaml")
extractor.save_report(yaml_config)

Command-Line Interface

FailExtract includes a feature-aware CLI that adapts to your installed extras:

# Check what features you have installed
failextract features

# Generate JSON report (always available)
failextract report --format json --output failures.json

# Show failure statistics
failextract stats

# List all captured failures
failextract list --format table

# Clear stored failure data
failextract clear --confirm

CI/CD Integration Examples

Basic CI/CD (Core Only):

# GitHub Actions example - basic JSON reporting
- name: Generate failure report
  if: always()
  run: |
    failextract report --format json --output test-failures.json
    failextract stats

Enhanced CI/CD (Multiple Formats):

# GitHub Actions with multiple formats
- name: Generate comprehensive failure reports
  if: always()
  run: |
    failextract report --format json --output test-failures.json
    failextract report --format markdown --output test-failures.md
    failextract report --format xml --output test-failures.xml

Progressive Enhancement Examples

Start Simple:

# Just the basics - lightweight and fast
from failextract import extract_on_failure

@extract_on_failure  
def test_basic():
    assert 1 == 2, "This will capture failure details"

Add YAML Formatting:

pip install failextract[formatters]
# Now use YAML output format
from failextract import FailureExtractor, OutputConfig

extractor = FailureExtractor()
config = OutputConfig("report.yaml", format="yaml", include_source=True)
extractor.save_report(config)

Add Rich CLI Output:

pip install failextract[cli]
# Now get enhanced terminal output
failextract report --format json --output failures.json
failextract stats  # Enhanced with rich formatting

Documentation

  • Full Documentation: Complete documentation with tutorials and API reference
  • Examples: Working examples in the examples/ directory
  • API Reference: Comprehensive API documentation with examples
  • Architecture Guide: Design patterns and extension points

Contributing

We welcome contributions! Please see our contributing guidelines for details on setting up the development environment and submitting pull requests.

Development Setup

# Clone the repository
git clone <repository-url>
cd failextract

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in development mode with all features
pip install -e .[development,docs,all]

# Run tests
pytest

# Run linting and formatting
ruff check src/ tests/
ruff format src/ tests/

# Build documentation
cd docs && make html

Project Structure

failextract/
โ”œโ”€โ”€ src/failextract/           # Main package source
โ”‚   โ”œโ”€โ”€ __init__.py           # Public API exports
โ”‚   โ”œโ”€โ”€ cli.py                # Command-line interface
โ”‚   โ”œโ”€โ”€ configuration.py      # Configuration management
โ”‚   โ”œโ”€โ”€ failextract.py        # Core extraction functionality
โ”‚   โ”œโ”€โ”€ api/                  # API protocols and events
โ”‚   โ”œโ”€โ”€ core/                 # Core functionality
โ”‚   โ”‚   โ”œโ”€โ”€ analysis/         # Context analysis
โ”‚   โ”‚   โ”œโ”€โ”€ extraction/       # Failure extraction
โ”‚   โ”‚   โ””โ”€โ”€ formatters/       # Output formatters
โ”‚   โ””โ”€โ”€ integrations/         # Framework integrations
โ”œโ”€โ”€ tests/                    # Comprehensive test suite
โ”‚   โ”œโ”€โ”€ unit/                 # Unit tests
โ”‚   โ”œโ”€โ”€ integration/          # Integration tests
โ”‚   โ”œโ”€โ”€ performance/          # Performance tests
โ”‚   โ””โ”€โ”€ property/             # Property-based tests
โ”œโ”€โ”€ examples/                 # Working examples
โ”œโ”€โ”€ docs/                     # Documentation source
โ””โ”€โ”€ pyproject.toml           # Project configuration

Features by Extra

  • Core (always available): JSON, XML, CSV, Markdown formatters, CLI, basic extraction
  • [formatters]: YAML output format (pyyaml)
  • [config]: Enhanced configuration with Pydantic validation
  • [cli]: Rich terminal output formatting (rich, typer)
  • [development]: All development tools (pytest, ruff, mypy, etc.)
  • [docs]: Documentation building tools (sphinx, themes, etc.)
  • [all]: All optional features combined

License

FailExtract is released under the Apache 2.0 License. See LICENSE for details.

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

failextract-1.0.0.tar.gz (250.0 kB view details)

Uploaded Source

Built Distribution

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

failextract-1.0.0-py3-none-any.whl (92.4 kB view details)

Uploaded Python 3

File details

Details for the file failextract-1.0.0.tar.gz.

File metadata

  • Download URL: failextract-1.0.0.tar.gz
  • Upload date:
  • Size: 250.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for failextract-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d7b311fd8d7cfe50d8243f4cec77f999669ff6091a5165f925b8acf452e497a3
MD5 d2097c18b4350b1af2db5711013e46f0
BLAKE2b-256 692eac641905c910b339224e1470f35681e7b14592c28980b1a6b519c48a65d9

See more details on using hashes here.

File details

Details for the file failextract-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: failextract-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 92.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.12

File hashes

Hashes for failextract-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4bab1afb4f92293b403d29c7aeeb8741eef0c3653f545fb4df31fb927b726d30
MD5 36b0ede551058265d342fb5699ba93d0
BLAKE2b-256 90b8b2b7b22059816459f836c16b25811195524586acb7328514a45f2e758bcc

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