A pytest plugin that automatically generates PyAnnotate type annotations from your test runs.
pytest-annotate is a pytest plugin that automatically generates PyAnnotate-compatible type annotations by observing runtime behavior during test execution. It solves the problem of manually adding type hints to large Python codebases by capturing type information from actual test runs and outputting it in a format that can be automatically applied.
Python developers working on codebases that need type annotations added, particularly those using pytest for testing and wanting to integrate type hinting into their workflow.
Developers choose pytest-annotate because it automates the tedious process of adding type annotations by leveraging existing test suites, reducing manual effort while ensuring annotations reflect actual usage patterns observed during testing.
Generate PyAnnotate annotations from your pytest tests.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Captures type information directly from function calls during pytest test runs, ensuring annotations are based on actual usage patterns as described in the README.
Works as a plugin with a simple --annotate-output flag, requiring no modifications to existing test code, making it easy to adopt.
Outputs all captured type data to a JSON file, allowing for bulk application to the codebase using PyAnnotate in a single step, saving manual effort.
Leverages test execution to derive annotations, reducing manual guesswork and improving accuracy for common use cases.
The quality of generated annotations is directly tied to test comprehensiveness; untested code paths yield no type data, leading to incomplete hints.
Requires a two-step workflow: run tests to generate JSON, then use PyAnnotate to apply annotations, adding complexity compared to direct annotation tools.
Only infers types from executed test cases, potentially missing edge cases or alternative type usages not covered in tests, as admitted in the philosophy.
Adding type capture during test execution may introduce overhead, slowing down test runs, especially for large suites, which isn't addressed in the README.