Decorators
@resource
Register a function as a dependency injection resource. Signature:
Returns: Decorated function registered as a resource
Example:
@sut
Register a function factory as a traced system-under-test resource. Signature:
Returns: Decorated function registered as a traced resource
Example:
@parametrize
Run a merit function with multiple parameter combinations. Signature:
Returns: Decorator that applies parametrization to the target function
Example:
@repeat
Run a merit function multiple times to test consistency. Signature:
Returns: Decorator that applies repeat configuration to the target
Example:
@run_inline
Run a synchronous merit inline on the event-loop thread. By default, synchronous merits are offloaded to a worker thread viaasyncio.to_thread(...). Use @run_inline to opt out when thread affinity matters.
Signature:
Returns: Decorated sync function marked to run inline
Notes:
- Applies only to synchronous
def merit_*functions. async def merit_*functions already run on the event-loop thread.
@tag
Add tags to merit functions or classes for filtering and organization. Signature:
Returns: Decorator that adds tags to the target
Example:
@tag.skip
Skip a merit function with an optional reason. Signature:
Returns: Decorator that marks the target as skipped
Example:
@tag.xfail
Mark a merit as expected to fail. Signature:
Returns: Decorator that marks the target as expected to fail
Example:
Classes
Case
Container for test case inputs and reference data. Attributes:
Example:
CaseGroup
Container for grouping related cases with group-level references and a pass threshold. Type Parameters:
Attributes:
Example:
Scope
Enum defining resource lifecycle scopes. Values:
Example:
Runner
Execute discovered merits and return aMeritRun.
Signature:
timeout):
timeoutis a run-level limit (not per-test).- Cancellation is cooperative: on timeout, the run is marked
stopped_earlyand no new tests are started. - In-flight work may not stop immediately, especially synchronous merits already executing in worker threads.
run_idaccepts either aUUIDobject or UUID string.run()run_idoverrides constructorrun_id.- If neither is provided, Merit auto-generates a new UUID.
- If
save_to_db=Trueand the selected run UUID already exists,run()raisesValueError. run_id_exists()can be used as a preflight check before execution.
Functions
Imperative Outcome Control
Merit provides imperative functions to control test outcomes at runtime. These are different from decorators and are used for conditional control flow within tests.skip
Skip the current test imperatively. Signature:
Returns: Never returns (raises
SkipTest exception)
Example:
fail
Explicitly fail the current test. Signature:
Returns: Never returns (raises
FailTest exception)
Example:
xfail
Mark the current test as expected to fail and stop execution. Signature:
Returns: Never returns (raises
XFailTest exception)
Example:
merit.skip()(function) vs@merit.tag.skip()(decorator)merit.fail()(function) vs no decorator equivalentmerit.xfail()(function) vs@merit.tag.xfail()(decorator)
iter_cases
Decorator to run a merit function for each case. Signature:
Returns: Decorator that applies parametrization using the cases
Validation:
min_passesmust be>= 1min_passescannot exceed the number of providedcases
iter_case_groups
Decorator to run a merit function for each case group, iterating cases within each group. Signature:
Returns: Decorator that applies group-level iteration to the target function
Injected parameters:
Execution semantics:
- Each group produces a nested execution; within each group, cases are iterated using the group’s
min_passesthreshold. - The parent merit passes only if all groups pass (i.e. every group meets its own
min_passes).
- At least one group is required (empty call sets a deferred definition error)
SUT case validation
Validate case inputs by passing them to@sut(validate_cases=...). Validation runs during SUT resolution and raises if any case does not match the resolved callable/method signature.