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.

This initial release (v0.0.1) exists primarily to reserve the project name and clearly define the vision and scope of the project.


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
  • CLI interface for test generation
  • Configurable mock policies
  • Optional integrations with LLMs for test suggestions (future)

Current Status

Version 0.0.1

  • Placeholder release
  • Name reservation on PyPI
  • No functional implementation yet
  • API and architecture subject to change

Development will begin after this initial release.


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.0.tar.gz (6.4 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.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_forger-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 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.0.tar.gz
Algorithm Hash digest
SHA256 85c3de384985b54c4c8b334b9da86ed92b9c4fd6f468c5677af01d95745c2b21
MD5 cba013ceb6a3b5fa9244a4f336ea6934
BLAKE2b-256 ddf1804770c6bbe0fa2884c0682f58f4ade076407f6e714e7ee8ac3f4d78acb0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pytest_forger-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.8 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8a423175ae2bd7e3a96d63b63378962b99c7a7a0f3746602adf98d4455babeaa
MD5 fa80f4d481fcd3e717f822b4ead26bb5
BLAKE2b-256 01a80572f686848240f14f0e56b52f7f74a2a41874f240f446f3684f5e76e5aa

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