suite.expect¶
Standalone non-fatal expectation collector.
The ExpectCollector accumulates failing checks without stopping
execution, then reports all failures together at the end. It is
framework-agnostic — use it inside pytest suites, unittest cases, or
plain scripts.
Quick start:
from otto.suite.expect import ExpectCollector
collector = ExpectCollector()
collector.expect(1 == 1) # passes — no-op
collector.expect(2 + 2 == 5) # fails — recorded
collector.raise_if_failures() # raises AssertionError with report
Or use the module-level convenience function:
from otto.suite.expect import ExpectCollector, expect
collector = ExpectCollector()
expect(1 == 1, collector=collector)
expect(2 + 2 == 5, collector=collector)
collector.raise_if_failures()
-
class otto.suite.expect.ExpectCollector(logger=
None)¶ Bases:
objectCollects non-fatal expectation failures.
- Parameters:¶
logger – Optional
logging.Loggerfor warning output when a check fails. When None, failures are still recorded but not logged.
- failures : --is-rst--:py:class:`list`\ \[:py:class:`str`]¶
Recorded failure reports for the current run.
-
expect(condition, msg=
None, _stack_offset=1)¶ Record a non-fatal expectation.
Unlike
assert, a failingexpect()does not stop execution. All failures are collected and can be inspected viafailuresor raised together withraise_if_failures().- Parameters:¶
condition – Any truthy/falsy expression to evaluate.
msg – Optional human-friendly message printed alongside the auto-captured source line and locals — not a replacement.
_stack_offset – How many frames to skip when capturing caller context. Callers that wrap this method should increase the offset so the report points at their caller.
Examples
Direct usage:
collector = ExpectCollector() x = 42 collector.expect(x == 99, "math is broken") assert len(collector.failures) == 1 assert "x = 42" in collector.failures[0]Note
The auto-captured source line and locals are best-effort. Provide msg when the expression alone isn’t self-explanatory.
- Return type:¶
None
-
otto.suite.expect.expect(condition, msg=
None, *, collector)¶ Module-level convenience wrapper around
ExpectCollector.expect().Behaves identically to
collector.expect(condition, msg)but uses a functional call style. The collector keyword argument is required so that failure state is always explicit — there is no hidden global.- Parameters:¶
condition – Any truthy/falsy expression to evaluate.
msg – Optional human-friendly message.
collector – The
ExpectCollectorthat will record any failure.
- Return type:¶
None