Skip to main content

Comprehensive self-hosted testing platform for developers (Python SDK)

Project description

TestFn Python SDK

Comprehensive self-hosted testing platform for developers.

Overview

TestFn is a developer-first testing solution that combines test execution, analytics, and visual testing into a single self-hosted platform. This is the Python SDK for TestFn.

Features

  • Test Execution: Integration with pytest for discovery and execution.
  • Storage: Persistent storage of test runs and results using SQLAlchemy (SQLite default).
  • Analytics: Flaky test detection, performance regression analysis, and run metrics.
  • Reporters: Console and JSON reporters for real-time and post-run output.
  • Visual Testing: Pixel-by-pixel screenshot comparison and diff generation.

Installation

pip install testfn

Quick Start

Basic Test Execution

import asyncio
from testfn import test_fn

async def main():
    # Initialize runner
    runner = test_fn(framework="pytest")
    
    # Run tests matching a pattern
    run = await runner.run(["tests/**/*.py"])
    
    print(f"Pass rate: {run.summary.passed / run.summary.total * 100}%")

if __name__ == "__main__":
    asyncio.run(main())

Using Analytics

from testfn import Storage, AnalyticsEngine

async def analyze():
    storage = Storage()
    analytics = AnalyticsEngine(storage)
    
    # Detect flaky tests
    flaky = await analytics.detect_flaky("tests/test_ui.py::test_login")
    print(f"Flaky Score: {flaky.flaky_score}")
    print(f"Recommendation: {flaky.recommendation}")
    
    # Find performance regressions
    regressions = await analytics.find_regressions(
        baseline_run_id="run-1", 
        current_run_id="run-2"
    )
    for reg in regressions:
        print(f"Test {reg['test_id']} got {reg['change']:.1%} slower")

Visual Testing

from testfn import VisualTester

tester = VisualTester(baseline_dir="baselines", diff_dir="diffs")

# Compare two screenshots
passed, score, diff_path = tester.compare_screenshots(
    current_path="screenshots/current.png",
    name="homepage",
    threshold=0.1
)

if not passed:
    print(f"Visual regression detected! Diff at: {diff_path}")

Development

# Setup virtual environment
python3 -m venv .venv
source .venv/bin/activate

# Install dependencies
pip install -e .[dev]

# Run tests
pytest

License

MIT

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

testfn-0.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

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

testfn-0.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file testfn-0.0.1.tar.gz.

File metadata

  • Download URL: testfn-0.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for testfn-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4f62db85c9a1c1c4665a9931154b3e2156a6675445ef83a0ecd867ee6ccfdc5d
MD5 f2fd00ce14a6eb777abd6e4d965870e0
BLAKE2b-256 7a58c99d3a454dd4467c8f41893d986cb3b6735d1aed449a72b49e780e4ac92c

See more details on using hashes here.

File details

Details for the file testfn-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: testfn-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for testfn-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 12c8260aa4503021dbe144ffa5e5537a91d51faeff91a13ef40e902a3b7320f4
MD5 f2ddc1134cfa47dad3df73a3dd30f4cc
BLAKE2b-256 fd680e855627ea08a924681ed8f52fc61823674297b4288ef87ab836b45354f3

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