diff --git a/nix/tests/vm/lib/komorebi_vm/core/suite.py b/nix/tests/vm/lib/komorebi_vm/core/suite.py index 190866e2..3a518f66 100644 --- a/nix/tests/vm/lib/komorebi_vm/core/suite.py +++ b/nix/tests/vm/lib/komorebi_vm/core/suite.py @@ -18,20 +18,32 @@ class Step: scope: str run: Callable[[], object] + name: str = "" + + +def _name(fn: Callable[..., object]) -> str: + """`module.function` of a scenario or an extra, for the line that says what runs.""" + module = getattr(fn, "__module__", "").rsplit(".", 1)[-1] + return f"{module}.{getattr(fn, '__name__', '')}".strip(".") def shared(scenario: Callable[..., object], *args: object) -> Step: """A scenario of `komorebi_vm.core.scenarios`, called with `args`.""" - return Step("shared", lambda: scenario(*args)) + return Step("shared", lambda: scenario(*args), _name(scenario)) def platform_only(scope: str, extra: Callable[..., object], *args: object) -> Step: """What one platform adds: an extra of that platform, called with `args`, under its name.""" - return Step(scope, lambda: extra(*args)) + return Step(scope, lambda: extra(*args), _name(extra)) -def run_suite(checks: Checks, *steps: Step) -> None: - """Runs the steps in order, each with its scope on `checks`.""" +def run_suite(checks: Checks, *steps: Step) -> list[object]: + """Runs the steps in order, each with its scope on `checks`, and returns what each returned, + so that a later part of a suite can use the windows a scenario opened.""" + results = [] for step in steps: + if step.name: + print(f"== [{step.scope}] {step.name}") with checks.scoped(step.scope): - step.run() + results.append(step.run()) + return results diff --git a/nix/tests/vm/lib/tests/test_suite.py b/nix/tests/vm/lib/tests/test_suite.py index 052b9f46..d59c7011 100644 --- a/nix/tests/vm/lib/tests/test_suite.py +++ b/nix/tests/vm/lib/tests/test_suite.py @@ -74,3 +74,18 @@ def test_a_suite_runs_its_steps_in_order_each_in_its_own_scope() -> None: ) assert order == ["kde:first", "shared:second", "kde:third"] assert checks.scope == "" + + +def test_a_suite_returns_what_its_steps_returned() -> None: + checks = Checks() + results = run_suite(checks, shared(lambda: 1), platform_only("kde", lambda: "two")) + assert results == [1, "two"] + + +def test_a_step_says_what_it_runs(capsys: pytest.CaptureFixture[str]) -> None: + def scenario() -> None: + pass + + run_suite(Checks(), shared(scenario), platform_only("kde", scenario)) + out = capsys.readouterr().out + assert "== [shared] test_suite.scenario" in out and "== [kde] test_suite.scenario" in out