Skip to content

bunpy test

bunpy test [flags] [pattern...]

Description

Discovers and runs test files. A file is treated as a test if its name starts with test_ or ends with _test.py. Each function decorated with @test inside those files is a test case.

Flags

FlagDefaultDescription
--filter <substr>Only run tests whose name contains substr
--verbose, -voffPrint each test name as it runs
--bail, -boffStop after the first failure
--watch, -woffRe-run tests on file changes
--timeout <ms>5000Per-test timeout in milliseconds
--coverageoffEmit a coverage report (experimental)
--help, -hPrint help

Writing tests

from bunpy.test import test, expect

@test("adds two numbers")
def _():
    expect(1 + 1).to_be(2)

@test("raises on bad input")
def _():
    with expect.raises(ValueError):
        int("not a number")

Run:

bunpy test
# ✓ adds two numbers   (0.3 ms)
# ✓ raises on bad input (0.1 ms)
# 2 passed, 0 failed

Skipping tests

from bunpy.test import test, expect, skip

@test("not ready yet")
def _():
    skip("WIP")

Filter

Run only tests that match a substring:

bunpy test --filter "adds"

Verbose mode

bunpy test --verbose
# PASS  tests/test_math.py::adds two numbers   0.3 ms
# PASS  tests/test_math.py::raises on bad input 0.1 ms

Watch mode

Continuously re-runs tests on every save:

bunpy test --watch

Exit codes

CodeMeaning
0All tests passed
1One or more tests failed
2Internal error (compile or runner failure)