Skip to main content

Here’s the README in proper Markdown format ready to save as README.md:

# FastAPI Test Automation Library

A production-ready **CI/CD and batch testing framework** for FastAPI projects. This library automatically scans your FastAPI project, detects endpoints and Pydantic models, generates payloads, runs tests, validates responses, and generates detailed reports.  

It is designed to simplify automated API testing and improve quality assurance workflows for FastAPI applications.

---

## Features

- **Automatic Project Scanning**: Detects FastAPI apps and routers across your project.
- **Endpoint Extraction**: Automatically extracts all registered endpoints.
- **Pydantic Model Extraction**: Extracts request and response models for payload validation.
- **Payload Generation**: Generates test payloads for POST, PUT, PATCH requests.
- **Automated Testing**: Runs single, batch, or CI/CD style tests with retries and timeouts.
- **Validation**: 
  - HTTP status code validation
  - Response schema validation against Pydantic models
- **Authentication Support**: Supports JWT, API keys, and custom headers.
- **Reporting**: Generates JSON reports and prints a terminal summary.
- **CLI Integration**: Run tests easily from the command line.

---

## Installation

Install the library in your Python environment:

```bash
pip install fastapptest

Ensure your FastAPI project is accessible and all dependencies are installed.


CLI Usage

CI/CD Testing

Run full CI/CD style tests for your FastAPI project:

ci_test <project_root> [--output <output_dir>]

Arguments:

  • project_root: Root directory of your FastAPI project.
  • --output: Directory to save CI/CD reports (default: ci_reports).

Example:

ci_test E:/Projects/my_fastapi_app --output ci_reports

This will:

  1. Scan your project for Python files.
  2. Detect FastAPI apps and routers.
  3. Extract endpoints and Pydantic models.
  4. Generate payloads for testing.
  5. Run automated tests.
  6. Validate responses and status codes.
  7. Generate a detailed JSON report and print a summary.

Batch Testing

Run tests using a JSON batch payload file:

batch_test <project_root> <batch_file> [--output <output_file>] [--auth <auth_json>]

Arguments:

  • project_root: Root directory of your FastAPI project.
  • batch_file: JSON file containing batch payloads.
  • --output: Path to save the batch test report (default: batch_reports/batch_test_report.json).
  • --auth: Optional JSON string for authentication headers, e.g., {"Authorization": "Bearer <token>"}.

Example:

batch_test E:/Projects/my_fastapi_app batch_payload.json --output batch_reports/report.json --auth '{"Authorization": "Bearer <token>"}'

Batch File Format:

[
    {
        "path": "/users",
        "method": "POST",
        "body": {"username": "test", "email": "test@example.com"}
    },
    {
        "path": "/users/{id}",
        "method": "GET",
        "path_params": {"id": 1}
    }
]

Library Usage

You can also use the library programmatically:

CI/CD Runner

from fastapptest.cli.ci_runner import run_ci_cd_tests

run_ci_cd_tests(
    project_root="E:/Projects/my_fastapi_app",
    output_dir="ci_reports",
    auth={"Authorization": "Bearer <token>"},
    fail_fast=True
)

Batch Runner

from fastapptest.cli.batch_runner import run_batch_tests

run_batch_tests(
    project_root="E:/Projects/my_fastapi_app",
    batch_file="batch_payload.json",
    output_file="batch_reports/report.json",
    auth={"Authorization": "Bearer <token>"}
)

Authentication

Supports common authentication methods:

  • Bearer Token (JWT) Add in auth dict: {"Authorization": "Bearer <token>"}

  • API Key Add in auth dict: {"X-API-KEY": "<your-api-key>"}

Auth headers will be automatically added to all requests.


Configuration Options

CI/CD Runner

Parameter Type Default Description
project_root str None Root directory of the FastAPI project
output_dir str ci_reports Directory to save CI/CD JSON report
auth dict None Optional auth headers (JWT/API keys)
fail_fast bool False Stop execution on first test failure

Batch Runner

Parameter Type Default Description
project_root str None Root directory of the FastAPI project
batch_file str None JSON file containing batch payloads
output_file str batch_reports/batch_test_report.json Path to save JSON batch report
auth dict None Optional auth headers (JWT/API keys)

Reports

  • JSON Reports: Contain full details of each request:

    • status_code
    • status_valid
    • schema_valid
    • response
    • error
  • Terminal Summary: Quick overview of tests with pass/fail indicators.


Recommended Workflow

  1. Install the library in your project environment.
  2. Create batch payloads for your endpoints.
  3. Run ci_test during CI/CD pipeline for automated validation.
  4. Use batch_test for targeted testing with predefined payloads.
  5. Review JSON reports and fix failing endpoints.
  6. Integrate into your GitHub Actions, Jenkins, or GitLab CI pipeline for automated testing.

Dependencies

  • Python 3.9+
  • FastAPI
  • requests
  • Standard Python libraries (pathlib, json, typing)

License

This library is released under the MIT License.


---

If you want, I can also **create a ready-to-go `docs/` folder** with:

- Example payloads
- CI/CD pipeline YAML snippets (GitHub Actions, GitLab, Jenkins)
- Full usage guide  

This will make your repository **professional and production-ready**.  

Do you want me to create that next?

Release files for fastapptest 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapptest 2.0.0
File Size Uploaded
fastapptest-2.0.0.tar.gz 28.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapptest 2.0.0
File Interpreter ABI Platform
fastapptest-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 70.7 kB

Release files / fastapptest-2.0.0.tar.gz

Download URL fastapptest-2.0.0.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c30c3a95051e1c84d0d47d0bc78b5f94288ce366322cc3e7225b09d696f37e09
BLAKE2b-256 checksum
How to use checksums
46a358abbc5721db8f334745cbe55f405f11b18c21f89e7a36fc12fc6705a360
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / fastapptest-2.0.0-py3-none-any.whl

Download URL fastapptest-2.0.0-py3-none-any.whl
Size 42.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
115b14d250a6f9b83430dc20f11a0a495ded6b00ae2cb843f3bd8ac2a723356b
BLAKE2b-256 checksum
How to use checksums
ea03172c83d536536cb812cfe84fe115ff853c854752fbc895a11c33ca03f3b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page