Skip to main content

A library for property-based testing of Python programs

Project description

GitHub PyPI PyPI - Downloads Discord GitHub Sponsors Documentation Status

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 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 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 import prop

@prop("addition is commutative")
def test_add_commute(x: int, y: int):
    return x + y == y + x

Custom Domains

from minigun import prop, context, domain as d

@context(d.int_range(1, 100), d.int_range(1, 100))
@prop("division reverses multiplication")
def test_div(x: int, y: int):
    return (x * y) // y == x

Combining Properties

from minigun 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

minigun_soren_n-2.5.0.tar.gz (73.4 kB view details)

Uploaded Source

Built Distribution

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

minigun_soren_n-2.5.0-py3-none-any.whl (77.7 kB view details)

Uploaded Python 3

File details

Details for the file minigun_soren_n-2.5.0.tar.gz.

File metadata

  • Download URL: minigun_soren_n-2.5.0.tar.gz
  • Upload date:
  • Size: 73.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for minigun_soren_n-2.5.0.tar.gz
Algorithm Hash digest
SHA256 4c74fe249bcd096178aa0310cf77b1b8667c3febdd3553eff4888b65b6c01852
MD5 dcea42d94d42f83a2883a7708b6eb19c
BLAKE2b-256 b2d95bbd44ca3b659ad2c3419146fd90d042246598d20cb29f79b95a7228d1df

See more details on using hashes here.

File details

Details for the file minigun_soren_n-2.5.0-py3-none-any.whl.

File metadata

  • Download URL: minigun_soren_n-2.5.0-py3-none-any.whl
  • Upload date:
  • Size: 77.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for minigun_soren_n-2.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 79efa49087a7c667d1b276bb50cec091a387e8c2f24ef9eb59453c548d2a4a5f
MD5 d7598a62406f725fa937af1aff2bb0cc
BLAKE2b-256 0262cab4de3ef2f9eb30866796de1c287767ef51b012b80b5214f3b7877ff134

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