Skip to content

Testing

rn_forge.commons.testing

Test utilities: a persistent output-path fixture and assertpy integration.

Intended for use in conftest.py or test files — not imported by the main package at runtime.

Usage::

# conftest.py
from rn_forge.commons.testing import output_path  # noqa: F401 — registers fixture

# test_something.py
from rn_forge.commons.testing import assert_that, soft_assertions

def test_example(output_path):
    result_file = output_path / "result.json"
    result_file.write_text('{"ok": true}')
    assert_that(result_file.read_text()).contains("ok")

Optional dependency: assertpy. Install with pip install rn-forge-commons[testing].

assert_that(val, description='')

Begin a fluent assertpy assertion chain on val.

Supports chaining multiple assertions in a single readable statement::

assert_that("foobar").is_length(6).starts_with("foo").ends_with("bar")
assert_that([1, 2, 3]).is_not_empty().contains(2).is_sorted()
assert_that(path).exists().is_file()

Parameters:

Name Type Description Default
val Any

The value under test.

required
description str

Optional label included in failure messages.

''

Raises:

Type Description
ImportError

If assertpy is not installed.

output_path(request)

Provide a persistent, per-test output directory under .tmp/<scope>/tests/output/.

Unlike tmp_path, the directory is not cleaned up after the test run — useful for inspecting generated files when debugging failures.

Path format: <rootdir>/.tmp/<scope>/tests/output/<sanitised-node-id>/

Import this fixture into conftest.py to make it available project-wide::

# conftest.py
from rn_forge.commons.testing import output_path  # noqa: F401

raise_(exc)

Raise exc; usable from a lambda where a statement is not allowed.

soft_assertions()

Return a context manager that collects all assertion failures before raising.

Use when you want to verify multiple conditions and see all failures at once rather than stopping at the first::

with soft_assertions():
    assert_that(response.status_code).is_equal_to(200)
    assert_that(response.json()).contains_key("data")
    assert_that(result.count).is_greater_than(0)

Raises:

Type Description
ImportError

If assertpy is not installed.