A library for property-based testing of Python programs
Project description
Minigun
A QuickCheck-like library for property-based unit-testing of Python programs.
Minigun is inspired by QCheck, which in turn was inspired by QuickCheck. Both are libraries that provide implementations for performing property-based unit-testing; for OCaml and Haskell respectively.
If you would like a bit of motivation as to why you should use a QuickCheck-like system for testing your project, then I would recommend that you watch:
If you wish to learn more about the subject, I can recommend Jan Midtgaard's lecture materials; it is OCaml based but translates easily to other QuickCheck-like libraries for other languages.
Install
Minigun is currently only supported for Python >=3.12. It is distributed with pip and can be installed with the following example command:
pip install minigun-soren-n
Quick Start
Using the CLI (Recommended)
Create a test module in tests/ directory:
# tests/my_tests.py
from minigun.specify import prop, check, conj
@prop("reversing a list twice gives the original")
def test_reverse(lst: list[int]):
return list(reversed(list(reversed(lst)))) == lst
@prop("list length distributes over concatenation")
def test_length(xs: list[int], ys: list[int]):
return len(xs + ys) == len(xs) + len(ys)
def test():
return check(conj(test_reverse, test_length))
Run your tests with time budget:
minigun --time-budget 30
Using as a Library
from minigun.specify import prop, check
@prop("reversing a list twice gives the original")
def test_reverse(lst: list[int]):
return list(reversed(list(reversed(lst)))) == lst
if __name__ == "__main__":
success = check(test_reverse)
exit(0 if success else 1)
Run directly:
python my_tests.py
Documentation
Full documentation and tutorials at Read The Docs.
Usage Guide
CLI Test Runner
# Run all tests in ./tests directory
minigun --time-budget 30
# Run tests from a different directory
minigun --time-budget 60 --test-dir my_tests
# Run specific test modules
minigun --time-budget 45 --modules my_tests other_tests
# List available test modules
minigun --list-modules
# Quiet mode (for CI/CD)
minigun --time-budget 60 --quiet
# JSON output (for automation)
minigun --time-budget 30 --json
The CLI discovers Python files in the test directory that contain a test() function.
Advanced: Manual Orchestrator Usage
For programmatic control, use the orchestrator directly:
# my_test_runner.py
from minigun.orchestrator import TestOrchestrator, OrchestrationConfig, TestModule
from minigun.specify import prop, check
@prop("your property")
def my_property(x: int):
return x + 0 == x
def run_my_property():
return check(my_property)
if __name__ == "__main__":
config = OrchestrationConfig(
time_budget=30.0,
verbose=True
)
modules = [TestModule("my_tests", run_my_property)]
orchestrator = TestOrchestrator(config)
success = orchestrator.execute_tests(modules)
exit(0 if success else 1)
Writing Tests
Basic Properties
from minigun.specify import prop
@prop("addition is commutative")
def test_add_commute(x: int, y: int):
return x + y == y + x
Custom Domains
import minigun.domain as d
from minigun.specify import prop, context
@context(d.int(1, 100), d.int(1, 100))
@prop("division reverses multiplication")
def test_div(x: int, y: int):
return (x * y) // y == x
Combining Properties
from minigun.specify import prop, check, conj
@prop("property 1")
def test_1(x: int):
return x + 0 == x
@prop("property 2")
def test_2(x: int):
return x * 1 == x
# Check both together
success = check(conj(test_1, test_2))
FAQ
Q: What's a good time budget?
A: Start with 30-60 seconds for quick feedback. Use 2-5 minutes for thorough testing in CI/CD.
Q: How do I test larger input spaces?
A: Increase the time budget. The system automatically runs more test attempts when given more time.
Q: Can I customize test generation?
A: Yes, use the @context decorator with domain specifications. See documentation for details.
Real-World Usage
The following projects use Minigun for testing:
If you have used Minigun for testing a public project, please file an issue with a link to add it to this list.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minigun_soren_n-2.4.2.tar.gz.
File metadata
- Download URL: minigun_soren_n-2.4.2.tar.gz
- Upload date:
- Size: 72.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d88dcb2c4a06b6bbadb57122348c8c6d88b976c1e03be091fe0c50c3219c7a92
|
|
| MD5 |
36129d10a44944518cf182c8e8d6e8ff
|
|
| BLAKE2b-256 |
895a22a1dd2072489a8d6687a351bdde1842528292610d01502d49c160372f57
|
File details
Details for the file minigun_soren_n-2.4.2-py3-none-any.whl.
File metadata
- Download URL: minigun_soren_n-2.4.2-py3-none-any.whl
- Upload date:
- Size: 76.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
131126eecd62a71157cbe6d640e310a48102bc41e0172541bd234a10b98632ff
|
|
| MD5 |
88815a0921dac2ba6429f687b3d51166
|
|
| BLAKE2b-256 |
c8ed28ed5170b7d73cd43c6aa8b3f9423d8ea3a722a85f73719ee530a04dad03
|