Skip to main content

Framework for fast Е2Е API testing

Project description

E2Efast

PyPI version Python versions GitHub Actions Coverage Status License: MIT Downloads Code style: ruff

Generate Python HTTP clients, fixtures, and integration tests from a single OpenAPI specification

🚀 Overview

E2Efast wraps the restcodegen toolkit and adds project-specific generators that organise REST clients, user-facing facades, pytest fixtures, and optional integration tests. One CLI command keeps these artefacts in sync so teams can iterate quickly on backend contracts.

✨ Key Features

  • One-command workflow – Generate clients, fixtures, and tests with a single CLI invocation.
  • Safe regeneration – Internal clients are regenerated automatically while editable facades live under framework/clients/http for manual customisations.
  • Fixture suite versions – Choose per-client fixtures (suite v1) or aggregated service fixtures and tests (suite v2).
  • Custom HTTP layer – Override a single ClientClass alias to switch between httpx.Client, AsyncClient, or your own subclass across all fixtures.

📦 Installation

Install project dependencies with Poetry:

poetry install

🔧 CLI Usage

Run the generator by providing the service name and OpenAPI spec location:

poetry run e2efast customers --spec ./crm_v2_service.json

Generate fixtures alongside the clients:

poetry run e2efast customers --spec ./crm_v2_service.json --with-fixtures --suite-version v2

Add service-oriented tests (fixtures implied):

poetry run e2efast customers --spec ./crm_v2_service.json --with-tests --suite-version v2

Command Options

Parameter Description Required Default
service (argument) Logical service name used for packages/modules
--spec / spec_url Path or URL to the OpenAPI document
--with-fixtures Generate fixtures in addition to clients False
--with-tests Generate tests (fixtures implied) False
--suite-version Fixture/test style: v1 (per-client) or v2 (service facade) v2

The CLI parses the specification once and reuses the resulting parser for each generator, ensuring all outputs remain consistent.

📁 Generated Structure

framework/
  clients/http/        # Editable facade clients (safe to modify)
  fixtures/http/       # Generated pytest fixtures + base ClientClass hook
internal/
  clients/http/        # Auto-generated REST clients and models
tests/
  http/               # Optional pytest suite generated when --with-tests is enabled

Re-run the CLI whenever the OpenAPI spec changes; generated files are overwritten, while your custom facades remain intact.

🔄 Custom HTTP Client

Every fixture imports ClientClass from framework/fixtures/http/base.py. Update this alias to point at any httpx.Client subclass and regenerated fixtures automatically adopt the change.

import httpx

ClientClass = httpx.Client

# Example override:
# from httpx import AsyncClient
# ClientClass = AsyncClient

The base.py file is generated only when missing, so manual overrides are preserved across subsequent runs.

🧩 Wiring Fixtures into pytest

Add the generated fixture package to your test suite via pytest_plugins so they auto-register during collection:

# conftest.py
pytest_plugins = ["framework.fixtures.http.service_name"]

Replace service_name with the snake_case module generated in framework/fixtures/http (for example the CLI run above produces framework/fixtures/http/customers.py, so use pytest_plugins = ["framework.fixtures.http.customers"]).

🌐 Environment Variables

Each generated fixture module reads a service-specific base URL from os.getenv("<SERVICE_NAME>_BASE_URL"). Define this environment variable before running fixtures or the generated tests—for example:

export CUSTOMERS_BASE_URL="https://api.example.test"

The variable name is derived from the snake_case service module uppercased with _BASE_URL appended (e.g. customersCUSTOMERS_BASE_URL).

🛠️ Development Workflow

poetry install           # Install dependencies
poetry run pytest        # Run tests
poetry run ruff check .  # Lint (example command)

Generators call format_file on their output directories to keep generated code tidy automatically.

📄 License

This project is distributed under the MIT 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

e2efast-0.2.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

e2efast-0.2.1-py3-none-any.whl (26.5 kB view details)

Uploaded Python 3

File details

Details for the file e2efast-0.2.1.tar.gz.

File metadata

  • Download URL: e2efast-0.2.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for e2efast-0.2.1.tar.gz
Algorithm Hash digest
SHA256 3bc2772abde71d188e580e4abd4de4810143903a22506b6289c2a91a0b61c1d8
MD5 704be695dc894a5d201552738f8eb0d1
BLAKE2b-256 a5933fcaf1405469c17353570fb027ac1ea2ceb334894e2408d0acf0936f4f42

See more details on using hashes here.

File details

Details for the file e2efast-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: e2efast-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 26.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for e2efast-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da950502d3a5f4d6244450540d6e9e43f0f4b89c8d7ce844638f5b57e8bdb205
MD5 985b1ad86eacd3af3733eb22a805476e
BLAKE2b-256 90f125d6f8aa96ded0e1865b424c86714b840ba642af4414cfcc6435df85fc74

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