test: add fast lane and duration visibility (#3659)

This commit is contained in:
Alexandre Teixeira
2026-06-09 19:11:47 +01:00
committed by GitHub
parent 9e74a327f8
commit cdfda4bd16
5 changed files with 252 additions and 7 deletions
+135
View File
@@ -47,6 +47,21 @@ def test_no_selection_marker_expression_is_none():
assert build_marker_expression(None, None) is None
def test_fast_only_marker_expression():
assert build_marker_expression(None, None, fast=True) == "not slow"
def test_fast_composes_with_area():
assert build_marker_expression("services", None, fast=True) == "area_services and not slow"
def test_fast_composes_with_area_and_sub_area():
assert (
build_marker_expression("services", "cookbook", fast=True)
== "area_services and sub_cookbook and not slow"
)
# --- command construction --------------------------------------------------
@@ -94,6 +109,47 @@ def test_default_python_is_current_interpreter():
assert command[0] == sys.executable
# --- fast lane and duration visibility -------------------------------------
def test_fast_only_command():
assert _cmd(fast=True) == [PY, "-m", "pytest", "-m", "not slow"]
def test_fast_with_area_command():
assert _cmd(area="services", fast=True) == [
PY, "-m", "pytest", "-m", "area_services and not slow",
]
def test_fast_with_area_and_sub_area_command():
assert _cmd(area="services", sub_area="cookbook", fast=True) == [
PY, "-m", "pytest", "-m", "area_services and sub_cookbook and not slow",
]
def test_durations_appends_flag():
assert _cmd(fast=True, durations=25) == [
PY, "-m", "pytest", "-m", "not slow", "--durations=25",
]
def test_durations_min_appends_flag():
assert _cmd(fast=True, durations=25, durations_min=0.05) == [
PY, "-m", "pytest", "-m", "not slow", "--durations=25", "--durations-min=0.05",
]
def test_durations_is_not_a_focus_selector():
assert FocusSelection(durations=25).has_focus is False
assert FocusSelection(fast=True).has_focus is True
def test_durations_kept_before_passthrough_args():
command = _cmd(fast=True, durations=25, pytest_args=("-q",))
assert command == [PY, "-m", "pytest", "-m", "not slow", "--durations=25", "-q"]
# --- sub-area normalization ------------------------------------------------
@@ -216,3 +272,82 @@ def test_no_focus_selector_is_rejected():
run(["--", "-q"], executor=executor)
assert excinfo.value.code == 2
assert executor.calls == []
def test_fast_run_invokes_executor_with_not_slow():
executor = _FakeExecutor()
run(["--fast"], executor=executor)
assert executor.calls == [[sys.executable, "-m", "pytest", "-m", "not slow"]]
def test_fast_with_durations_run_invokes_executor():
executor = _FakeExecutor()
run(["--area", "services", "--fast", "--durations", "25"], executor=executor)
assert executor.calls == [[
sys.executable,
"-m",
"pytest",
"-m",
"area_services and not slow",
"--durations=25",
]]
def test_fast_durations_dry_run_prints_command(capsys):
executor = _FakeExecutor()
code = run(["--dry-run", "--fast", "--durations", "25"], executor=executor)
out = capsys.readouterr().out
assert code == 0
assert executor.calls == []
assert out == f"{sys.executable} -m pytest -m 'not slow' --durations=25\n"
def test_durations_alone_is_rejected_before_executor():
executor = _FakeExecutor()
with pytest.raises(SystemExit) as excinfo:
run(["--durations", "25"], executor=executor)
assert excinfo.value.code == 2
assert executor.calls == []
def test_durations_zero_is_allowed_means_show_all():
executor = _FakeExecutor()
run(["--fast", "--durations", "0"], executor=executor)
assert executor.calls == [[
sys.executable, "-m", "pytest", "-m", "not slow", "--durations=0",
]]
@pytest.mark.parametrize("flag,value", [("--durations", "-1"), ("--durations-min", "-0.5")])
def test_negative_duration_values_are_rejected(flag, value):
executor = _FakeExecutor()
with pytest.raises(SystemExit) as excinfo:
run(["--fast", flag, value], executor=executor)
assert excinfo.value.code == 2
assert executor.calls == []
@pytest.mark.parametrize("argv", [
["--fast", "--durations-min", "0.05"],
["--area", "services", "--durations-min", "0.05"],
])
def test_durations_min_without_durations_is_rejected(argv):
executor = _FakeExecutor()
with pytest.raises(SystemExit) as excinfo:
run(argv, executor=executor)
assert excinfo.value.code == 2
assert executor.calls == []
def test_durations_min_with_durations_is_allowed():
executor = _FakeExecutor()
run(["--fast", "--durations", "25", "--durations-min", "0.05"], executor=executor)
assert executor.calls == [[
sys.executable,
"-m",
"pytest",
"-m",
"not slow",
"--durations=25",
"--durations-min=0.05",
]]