"""Stdlib assertion helpers for the beam lane's bare-style test files. Why this file exists (Q128, 2026-10-30): four of this lane's test files imported `pytest` only for `pytest.raises` and one `pytest.fail`. On an interpreter without pytest those four modules fail at import, so the lane's own gate could not grade them at all -- `beam/CHECK` exited 2 with "pytest not importable -- cannot grade" and ran zero of the lane's cells. The surface actually used is two names, so it lives here on the standard library instead of behind a third-party package. `raises` is a context manager that fails unless the expected exception is raised, matching `pytest.raises(X)` for the way these files use it (no `match=`, no `as`). `fail` raises AssertionError with the message, matching `pytest.fail`. Both work under `unittest`, under `pytest`, and as bare `assert`-style modules run by `run_lane_tests.py`. """ import contextlib @contextlib.contextmanager def raises(exc_type): """Fail unless the block raises ``exc_type`` (or a subclass).""" try: yield except exc_type: return raise AssertionError( "expected %s to be raised; nothing was raised" % (exc_type.__name__,) ) def fail(msg=""): """Fail the current test with ``msg``.""" raise AssertionError(msg)