punit.facts#

Facts are tests that validate an invariant arrangement of state.

State is usually hardcoded as part of the test definition itself. Unlike Theories, Facts do not require data providers; each decorated function runs exactly once.

Example#

from punit import fact

@fact
def test_equality():
    assert 1 == 1

class MyTestClass:
    @fact
    def test_method(self):
        assert True
class Fact(target)#

Bases: object

Wraps a test function or method decorated with @fact.

Example#

from punit import fact

@fact
def myFunction():
    assert 1 == 1
property metadata: CallableMetadata#
property target: LambdaType | MethodType | BuiltinMethodType | Callable#
async execute(module)#
Return type:

Any | None

fact(target)#

Decorates a function or method as a ‘Fact-based’ test.

Return type:

Callable

Args:

target: The function or method to decorate as a Fact test

Returns:

The original, undecorated target – no wrapper is installed

Example#

from punit import fact

@fact
def myFunction():
    assert 1 == 1

class MyClass:
    @fact
    def myMethod(self):
        assert 1 == 1
Raises:
Exception: If target is not a function/method, or if it already carries

another pUnit decorator attribute.

class FactManager#

Bases: object

static instance()#
Return type:

FactManager

property excludeTraits: list[Trait]#
property includeTraits: list[Trait]#
get(module_name)#
Return type:

list[Fact]

put(fact)#
Return type:

None