API Reference
test decorator
Decorator for marking functions as tests.
Tryke discovers functions decorated with @test (or prefixed with
test_) during collection.
Attributes:
| Name | Type | Description |
|---|---|---|
skip |
Skip a test unconditionally. |
|
todo |
Mark a test as a placeholder. |
|
xfail |
Mark a test as expected to fail. |
Example
__call__
Register a function as a test.
Can be used as a bare decorator (@test) or called with keyword
arguments (@test(name="...", tags=[...])) to set metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
The test function (when used as a bare decorator). |
None
|
|
name
|
Optional display name for the test. |
None
|
|
tags
|
Optional list of tags for filtering with |
None
|
skip_if
Skip a test conditionally, evaluated at import time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
condition
|
bool
|
When |
required |
reason
|
str
|
Optional reason shown in test output. |
''
|
Skip a test unconditionally.
Can be used as a bare decorator or called with a reason string.
Example
__call__
__call__(
fn_or_reason: _Fn | str | None = None,
/,
*,
reason: str | None = None,
name: str | None = None,
tags: list[str] | None = None,
) -> _Fn | _Decorator
Mark a test to be skipped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn_or_reason
|
_Fn | str | None
|
The test function (when used as a bare decorator) or a reason string (when called with parentheses). |
None
|
reason
|
str | None
|
Reason for skipping (alternative to positional string). |
None
|
name
|
str | None
|
Optional test name override. |
None
|
tags
|
list[str] | None
|
Optional list of tags for filtering. |
None
|
Mark a test as a placeholder — it will be collected but not executed.
Can be used as a bare decorator or called with a description string.
Example
__call__
__call__(
fn_or_desc: _Fn | str | None = None,
/,
*,
description: str | None = None,
name: str | None = None,
tags: list[str] | None = None,
) -> _Fn | _Decorator
Mark a test as a todo placeholder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn_or_desc
|
_Fn | str | None
|
The test function (when used as a bare decorator) or a description string (when called with parentheses). |
None
|
description
|
str | None
|
Description of what needs to be done (alternative to positional string). |
None
|
name
|
str | None
|
Optional test name override. |
None
|
tags
|
list[str] | None
|
Optional list of tags for filtering. |
None
|
Mark a test as expected to fail.
Can be used as a bare decorator or called with a reason string.
__call__
__call__(
fn_or_reason: _Fn | str | None = None,
/,
*,
reason: str | None = None,
name: str | None = None,
tags: list[str] | None = None,
) -> _Fn | _Decorator
Mark a test as expected to fail.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn_or_reason
|
_Fn | str | None
|
The test function (when used as a bare decorator) or a reason string (when called with parentheses). |
None
|
reason
|
str | None
|
Reason the test is expected to fail (alternative to positional string). |
None
|
name
|
str | None
|
Optional test name override. |
None
|
tags
|
list[str] | None
|
Optional list of tags for filtering. |
None
|
expect assertions
Create an Expectation for expr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
T
|
The value to make assertions on. |
required |
name
|
str | None
|
Optional label for the assertion (used by the Rust-side discovery to extract assertion labels from source code; unused at runtime). |
None
|
Returns:
| Type | Description |
|---|---|
Expectation[T]
|
An |
Example
from tryke import expect expect(1 + 1).to_equal(2) MatchResult(ok) expect("hello").to_contain("ell") MatchResult(ok)
Chainable assertion wrapper created by expect.
Every assertion method returns a MatchResult.
Use .not_ to negate any assertion.
Example
from tryke import expect expect(1 + 1).to_equal(2) MatchResult(ok) expect(None).not_.to_be_truthy() MatchResult(ok)
not_
property
Negate the next assertion.
Example
from tryke import expect expect(1).not_.to_equal(2) MatchResult(ok) expect(None).not_.to_be_truthy() MatchResult(ok)
to_equal
Deep equality check (==).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
T
|
The value to compare against. |
required |
Example
from tryke import expect expect(1 + 1).to_equal(2) MatchResult(ok) expect([1, 2]).to_equal([1, 2]) MatchResult(ok)
to_be
Identity check (is).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
object
|
The object to compare identity against. |
required |
Example
from tryke import expect sentinel = object() expect(sentinel).to_be(sentinel) MatchResult(ok)
to_be_truthy
Assert the value is truthy (bool(value) is True).
Example
from tryke import expect expect(1).to_be_truthy() MatchResult(ok) expect([1]).to_be_truthy() MatchResult(ok)
to_be_falsy
Assert the value is falsy (bool(value) is False).
Example
from tryke import expect expect(0).to_be_falsy() MatchResult(ok) expect("").to_be_falsy() MatchResult(ok)
to_be_none
Assert the value is None.
Example
from tryke import expect expect(None).to_be_none() MatchResult(ok) expect(42).not_.to_be_none() MatchResult(ok)
to_be_greater_than
Assert the value is greater than n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
T
|
The value to compare against. |
required |
Example
from tryke import expect expect(5).to_be_greater_than(3) MatchResult(ok)
to_be_less_than
Assert the value is less than n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
T
|
The value to compare against. |
required |
Example
from tryke import expect expect(3).to_be_less_than(5) MatchResult(ok)
to_be_greater_than_or_equal
Assert the value is greater than or equal to n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
T
|
The value to compare against. |
required |
Example
from tryke import expect expect(5).to_be_greater_than_or_equal(5) MatchResult(ok)
to_be_less_than_or_equal
Assert the value is less than or equal to n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
T
|
The value to compare against. |
required |
Example
from tryke import expect expect(4).to_be_less_than_or_equal(5) MatchResult(ok)
to_contain
Assert the value contains item.
Works on lists, strings, and any container supporting in.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
T
|
The item to search for. |
required |
Example
from tryke import expect expect([1, 2, 3]).to_contain(2) MatchResult(ok) expect("hello world").to_contain("world") MatchResult(ok)
to_have_length
Assert the value has length n.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n
|
int
|
The expected length. |
required |
Example
from tryke import expect expect([1, 2, 3]).to_have_length(3) MatchResult(ok) expect("hello").to_have_length(5) MatchResult(ok)
to_match
Regex match against the string representation of the value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
A regular expression pattern. |
required |
Example
from tryke import expect expect("hello world").to_match(r"hello") MatchResult(ok) expect("foo123").to_match(r"\d+") MatchResult(ok)
to_raise
to_raise(
exc_type: type[BaseException] | None = None,
*,
match: str | None = None,
) -> MatchResult
Assert that a callable raises an exception.
Wrap the expression in a lambda.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
type[BaseException] | None
|
Expected exception type, or |
None
|
match
|
str | None
|
Regex pattern to match against the exception message. |
None
|
Example
from tryke import expect expect(lambda: int("abc")).to_raise(ValueError) MatchResult(ok) expect(lambda: 1 / 0).to_raise(ZeroDivisionError, match="division") MatchResult(ok) expect(lambda: None).not_.to_raise() MatchResult(ok)
Result of an assertion.
By default assertions are soft — a failing assertion records the
failure but does not stop the test. Call .fatal() to opt in to
immediate failure.