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.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


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.4.3.tar.gz (72.6 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.4.3-py3-none-any.whl (76.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minigun_soren_n-2.4.3.tar.gz
  • Upload date:
  • Size: 72.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.4.3.tar.gz
Algorithm Hash digest
SHA256 c6f5147c64dc03847173ed59e5099e320d2663513833ef9217b58c62bd826437
MD5 aae04318de578fa9fed2ae87c73026e5
BLAKE2b-256 f319049237e572b4099bb32be3a18676d7f6a2f9b9a246cd53ca8bc3e1f86166

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minigun_soren_n-2.4.3-py3-none-any.whl
  • Upload date:
  • Size: 76.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76be1a8687448f677897fc216f034e5326c4ef1f2a6bd841ccd221285c60ef03
MD5 1c4ae43b3f774cdf497b6f120407b05b
BLAKE2b-256 e98ec40910eaed6fd17e58bf21dc726e9ce00bf72273f25b6ec8f5f54cd3ba90

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