Skip to content

test(cli): tests assert outcome and raises match error - #2864

Merged
dan-petty merged 2 commits into
mainfrom
test/2171-tests-assert-outcome-and-match-raises
Oct 31, 2026
Merged

dan-petty merged 2 commits into
mainfrom
test/2171-tests-assert-outcome-and-match-raises

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Description

This pull request ensures that tests check their stated outcomes and that exception checks are specific.

  • Adds assertions to tests that did not assert their outcomes:
    • tests/commands/test_argo.py: test_valid_k8s_label_names and test_valid_k8s_resource_names assert return values are None.
    • tests/http/test_http_connection_pool.py: test_closing_an_empty_registry_is_harmless asserts the client registry is empty.
    • tests/k8s/test_k8s_security_stream.py: test_render_security_alerts_empty asserts empty alert output.
    • tests/ai/test_output.py: test_print_panel_fallback_on_exception asserts fallback panel text.
    • tests/ai/review/test_review_runner.py: test_rendering_helpers asserts rendered output.
    • tests/commands/test_vault_cmd.py: test_validate_vault_path_valid asserts valid path checks return None.
    • tests/core/test_docker_engine.py: test_remove_container_tolerates_already_reaped already asserts call names.
    • tests/http/test_http.py: test_public_https_url_allowed and test_public_http_url_allowed were replaced by egress tests in tests/http/test_http_egress.py.
  • Adds match= or exc.value.code checks to built-in exception pytest.raises sites across the test suite.
  • Configures Ruff PT011 (raises-require-match-for) in pyproject.toml for built-in exceptions.
  • Adds the test-function-has-assertion ast-grep rule and rule test to prevent test functions without assertions.

Verification

  • Criterion 1: Verified each named test with uv run pytest.
  • Criterion 2: Verified all built-in exception pytest.raises sites pass match= or verify exc.value.code.
  • Criterion 3: Verified Ruff PT011 fails on a scratch test with pytest.raises(KeyError) without match=.
  • Criterion 4: Verified ast-grep scan fails on a scratch test function without assertions, and ast-grep test passes.
  • Criterion 5: Verified three changed tests fail when their asserted behavior is broken (test_valid_k8s_label_names, test_validate_vault_path_valid, test_entry_main_version).

Closes #2171

@dan-petty dan-petty added type/test Type test: a new or changed test scope/cli Core CLI framework, Typer subcommands, options, and tables labels Oct 31, 2026
Each test asserts the outcome that its name states.
Each pytest.raises call of a built-in exception passes match or checks the exit code.
Configures Ruff PT011 to require match for built-in exceptions.
Adds an ast-grep rule to fail test functions without assertions.

Closes #2171
Registers test-function-has-assertion in invariant and construct test tables.
@dan-petty
dan-petty force-pushed the test/2171-tests-assert-outcome-and-match-raises branch from 8b5aea3 to e652b71 Compare October 31, 2026 13:56
@dan-petty
dan-petty marked this pull request as ready for review October 31, 2026 14:11
@dan-petty
dan-petty merged commit 00796a4 into main Oct 31, 2026
18 checks passed
@dan-petty
dan-petty deleted the test/2171-tests-assert-outcome-and-match-raises branch October 31, 2026 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope/cli Core CLI framework, Typer subcommands, options, and tables type/test Type test: a new or changed test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(cli): every test asserts its outcome, and each pytest.raises of a built-in exception names the message

1 participant