Skip to content

testudos.testing.assertions

testudos.testing.assertions

Test assertions: hard failures (test) and soft failures (expect).

Hard assertions raise AssertionError immediately (gtest ASSERT_* style). Soft assertions record failures and raise once when verify_all() is called (gtest EXPECT_* style). Pytest runs verify_all() automatically after each test.

TestAPI Objects

class TestAPI()

Hard assertion helpers for test scripts (gtest ASSERT_* style).

compare(a, b) fails if a != b; verify(condition) fails if not condition; fail(msg) always fails.

compare

def compare(a: Any, b: Any, msg: str | None = None) -> None

Assert that a equals b. Raises AssertionError if not.

verify

def verify(condition: bool, msg: str | None = None) -> None

Assert that condition is true. Raises AssertionError if false.

equal

def equal(a: Any, b: Any, msg: str | None = None) -> None

Alias for compare.

true

def true(condition: bool, msg: str | None = None) -> None

Alias for verify.

fail

def fail(msg: str | None = None) -> None

Fail the test with an optional message.

compare_images

def compare_images(actual_path: str,
baseline_path: str,
tolerance: float = 0.0,
msg: str | None = None) -> None

Compare two image files and fail the test if they differ.

compare_screenshot

def compare_screenshot(target: Any,
baseline_path: str,
temp_path: str | None = None,
tolerance: float = 0.0) -> None

Capture a screenshot of a Qt object and compare it to a baseline image.

ExpectAPI Objects

class ExpectAPI()

Soft assertion helpers (gtest EXPECT_* style).

Record failures without stopping the test. Call verify_all() to raise a single AssertionError listing all recorded failures (pytest does this automatically).

compare

def compare(a: Any, b: Any, msg: str | None = None) -> None

Record a failure if a does not equal b.

verify

def verify(condition: bool, msg: str | None = None) -> None

Record a failure if condition is false.

equal

def equal(a: Any, b: Any, msg: str | None = None) -> None

Alias for compare.

true

def true(condition: bool, msg: str | None = None) -> None

Alias for verify.

compare_images

def compare_images(actual_path: str,
baseline_path: str,
tolerance: float = 0.0,
msg: str | None = None) -> None

Record a failure if two image files differ.

compare_screenshot

def compare_screenshot(target: Any,
baseline_path: str,
temp_path: str | None = None,
tolerance: float = 0.0) -> None

Capture a screenshot and record a failure if it differs from baseline.

verify_all

def verify_all() -> None

Raise AssertionError if any soft assertion failed.

clear

def clear() -> None

Discard recorded failures.

failures

@property
def failures() -> list[str]

Return a copy of recorded failure messages.