Skip to main content

Automatic test scaffolding and mock generation for Python

Project description

pytest-forger

Version: 0.1.0 Status: First functional release with CLI


What is pytest-forger?

pytest-forger is a Python tool designed to forge PyTest-ready tests from existing Python source code.

The goal of the project is to reduce the friction and boilerplate involved in writing tests by automatically generating test scaffolding and mocks based on the structure of your code, while keeping the developer fully in control of the final behavior.


Project Vision

Writing tests is essential, but writing test boilerplate is often repetitive, time-consuming, and discouraging—especially in service-oriented architectures with repositories, external services, and layered dependencies.

pytest-forger aims to:

  • Analyze Python source code statically
  • Detect function and method dependencies
  • Identify external boundaries (repositories, services, adapters)
  • Automatically generate:
    • PyTest test files
    • Mocked dependencies
    • Executable test scaffolding

pytest-forger does not attempt to guess business logic or replace human reasoning.
Instead, it focuses on automating the mechanical and structural parts of testing.


Design Principles

pytest-forger is built around a few core principles:

  • Automation without magic
    Generated tests should be explicit, readable, and predictable.

  • Structure over semantics
    The tool understands code structure, not business intent.

  • Mocks at the boundaries
    External dependencies are mocked; internal logic remains real.

  • Developer ownership
    Generated tests are meant to be edited, extended, and owned by the developer.


Intended Use Cases

pytest-forger is especially useful for:

  • Service layers calling repositories or other services
  • Legacy codebases with little or no test coverage
  • Quickly bootstrapping tests for refactoring
  • Teams that want consistency in test structure
  • Developers who want to avoid repetitive PyTest boilerplate

What pytest-forger Is Not

To set clear expectations, pytest-forger is not:

  • A replacement for test design
  • A business-logic inference engine
  • A fully autonomous test generator
  • A PyTest plugin (at least initially)

pytest-forger generates starting points, not perfect tests.


Planned Capabilities (Future Versions)

These features are planned, not yet implemented:

  • Static analysis of function and method call graphs
  • Automatic mock generation for:
    • Repositories
    • External services
    • Imported functions
  • Minimal factory generation based on return type hints
  • PyTest-compatible test scaffolding
  • Configurable mock policies

Changelog

[0.1.0] - 2025-12-26

Added

  • Initial CLI implementation using Typer framework
  • ptf version command to display project version and information
  • ptf forge <source_file.py> command interface for test generation
  • Complete argument parsing system with options:
    • --function / -f - Target specific function for test generation
    • --output / -o - Custom output directory for generated tests
    • --overwrite / -w - Overwrite existing test files
    • --verbose / -v - Enable detailed output for debugging
  • Project structure with src/ layout
  • PyPI-ready packaging configuration in pyproject.toml
  • Dependencies: pytest>=7.4.0, typer>=0.9.0

Notes

  • ptf forge currently provides the interface without actual code analysis
  • This release establishes the foundation for implementing test generation
  • Installation via pip install -e . for development

🔧 Coming in v0.2.0

  • Actual Python source code analysis
  • Test skeleton generation from functions
  • Basic test file creation with proper imports
  • Support for simple function signatures

Philosophy

pytest-forger exists to answer one simple question:

“How much of testing can we automate without lying to ourselves?”

The answer is: a lot of the boring parts.


License

MIT License


Disclaimer

pytest-forger is an early-stage project under active design.
Breaking changes are expected in early versions.


Forge tests, not excuses.

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

pytest_forger-0.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

pytest_forger-0.1.1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest_forger-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for pytest_forger-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7c233cf2058de1afd18f3b2c41edfe9f5dedbcef0a819eef13cdd3b6c9e77e3c
MD5 488ffbc997adf26cd7ed074b9ecc00fb
BLAKE2b-256 055e86f6ef662bb4486686f97ab024580fc372765bdb4356ff78c2b42846f629

See more details on using hashes here.

File details

Details for the file pytest_forger-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pytest_forger-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b1e3f03b9229be835302a39bab97fd34da1c121aa0213b47f6edeca7b4540868
MD5 595ebcfc7519e412c7410cbc6d6c89b3
BLAKE2b-256 523fa70a3e9a5256cd37b8cc9df41b9a8cd998cdbd59c7c6f2ce79d1eae7981f

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