Skip to main content

Automatic pytest test generation from OpenAPI (Swagger) specifications

Project description

SwaggerForge

Automatic pytest test generation from OpenAPI (Swagger) specifications.

SwaggerForge is a Python library and command-line tool that reads an OpenAPI specification and generates ready-to-run pytest test files - one per resource covering positive, negative, boundary, and boolean scenarios grounded in established test-design techniques.

Features

  • Reads OpenAPI 3.x specifications in JSON or YAML
  • Resolves $ref references automatically
  • Generates one pytest file per resource tag
  • Produces six scenario types per endpoint where applicable:
    • Positive >>> valid request, expects a 2xx response and validates the response schema
    • Missing required field >>> omits a required field, expects 400
    • Wrong data type >>> sends a mistyped field, expects 400/422
    • Nonexistent resource >>> requests an unlikely identifier, expects 404
    • Boundary values >>> tests values at and just beyond declared numeric/length limits (Boundary Value Analysis)
    • Boolean coverage >>> exercises both true and false for boolean fields
  • Deterministic output: the same specification always produces identical tests
  • Generated files use session-scoped pytest fixtures and run with no manual edits

Requirements

  • Python 3.10 or newer

Installation

pip install swaggerforge

Usage

Generate tests from a specification, pointing at the base URL of the API under test:

swaggerforge generate --spec swagger.json --url http://localhost:8080

This reads swagger.json, writes one test_<resource>.py file per resource tag into the output directory (default: tests_generated/), and the files can be run immediately:

pytest tests_generated

Options

Option Description Default
--spec Path to the OpenAPI specification (JSON or YAML) (required)
--url Base URL of the API under test (required)
--output Directory for the generated test files tests_generated

How it works

SwaggerForge runs a six-stage pipeline: the specification is validated, parsed into an internal model (with $refs resolved), turned into test scenarios based on test-design techniques, rendered into pytest code via templates, and written to per-resource files.

Limitations

  • Targets OpenAPI 3.x with JSON request bodies
  • Authentication is not yet handled (planned)
  • Boundary tests require the specification to declare numeric/length constraints

License

This project is licensed under the MIT License - see the LICENSE file.

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

swaggerforge-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

swaggerforge-0.1.0-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file swaggerforge-0.1.0.tar.gz.

File metadata

  • Download URL: swaggerforge-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for swaggerforge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1113bc0611cfd8d41fb152fe0965e8d86dd7f3e9e1e9ff7e3e2980b77e2910ee
MD5 8e9fb19665ab1f56d26bbeef53abf773
BLAKE2b-256 f44fb416f93d64ad84fce311efb816ded46ed3f8ad109899fdc2d7823e78e935

See more details on using hashes here.

File details

Details for the file swaggerforge-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: swaggerforge-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for swaggerforge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20b397f5c0ecafa5355743f697fd513db81e44a880ce5835c1a4365911083828
MD5 a0bb97296bd60cb9610a4fa12fde36df
BLAKE2b-256 eb81ee6cd5f86e59635a5f61907fd2ea1856f6b61043b994e8ac8e60bac06337

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