Skip to main content

Decorators

@resource

Register a function as a dependency injection resource. Signature:
Parameters: Returns: Decorated function registered as a resource Example:

@sut

Register a function factory as a traced system-under-test resource. Signature:
Parameters: Returns: Decorated function registered as a traced resource Example:

@parametrize

Run a merit function with multiple parameter combinations. Signature:
Parameters: Returns: Decorator that applies parametrization to the target function Example:

@repeat

Run a merit function multiple times to test consistency. Signature:
Parameters: 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 via asyncio.to_thread(...). Use @run_inline to opt out when thread affinity matters. Signature:
Parameters: 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.
Example:

@tag

Add tags to merit functions or classes for filtering and organization. Signature:
Parameters: Returns: Decorator that adds tags to the target Example:
CLI Usage:

@tag.skip

Skip a merit function with an optional reason. Signature:
Parameters: Returns: Decorator that marks the target as skipped Example:

@tag.xfail

Mark a merit as expected to fail. Signature:
Parameters: 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 a MeritRun. Signature:
Timeout behavior (timeout):
  • timeout is a run-level limit (not per-test).
  • Cancellation is cooperative: on timeout, the run is marked stopped_early and no new tests are started.
  • In-flight work may not stop immediately, especially synchronous merits already executing in worker threads.
Run UUID behavior:
  • run_id accepts either a UUID object or UUID string.
  • run() run_id overrides constructor run_id.
  • If neither is provided, Merit auto-generates a new UUID.
  • If save_to_db=True and the selected run UUID already exists, run() raises ValueError.
  • run_id_exists() can be used as a preflight check before execution.
Example:

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:
Parameters: Returns: Never returns (raises SkipTest exception) Example:

fail

Explicitly fail the current test. Signature:
Parameters: Returns: Never returns (raises FailTest exception) Example:

xfail

Mark the current test as expected to fail and stop execution. Signature:
Parameters: Returns: Never returns (raises XFailTest exception) Example:
Note: These imperative functions are different from the decorators:
  • merit.skip() (function) vs @merit.tag.skip() (decorator)
  • merit.fail() (function) vs no decorator equivalent
  • merit.xfail() (function) vs @merit.tag.xfail() (decorator)
Use decorators for unconditional outcomes known at definition time. Use functions for conditional outcomes determined at runtime.

iter_cases

Decorator to run a merit function for each case. Signature:
Parameters: Returns: Decorator that applies parametrization using the cases Validation:
  • min_passes must be >= 1
  • min_passes cannot exceed the number of provided cases
Example:

iter_case_groups

Decorator to run a merit function for each case group, iterating cases within each group. Signature:
Parameters: 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_passes threshold.
  • The parent merit passes only if all groups pass (i.e. every group meets its own min_passes).
Validation:
  • At least one group is required (empty call sets a deferred definition error)
Example:

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.