Skip to content

test(cli): tests check error code exit code or match - #2876

Merged
dan-petty merged 1 commit into
mainfrom
test/2177-tests-check-error-code-or-match
Oct 31, 2026
Merged

dan-petty merged 1 commit into
mainfrom
test/2177-tests-check-error-code-or-match

Conversation

@dan-petty

Copy link
Copy Markdown
Owner

Description

This pull request ensures that each test of an error path verifies the error code, exit code, or error message.

  • Adds the test-pytest-raises-checks-error ast-grep rule and rule test to report any bare pytest.raises(...) without match= or an as ... target.
  • Registers the test-pytest-raises-checks-error rule in architectural invariants tests (CONST_TEST_CONSTRUCT_RULES and _VIOLATIONS).
  • Updates bare pytest.raises calls across the test suite to assert the machine-readable error_code for DevOpsCLIError instances, verify exit codes for typer.Exit, and assert error messages or attributes for library exceptions.
  • Archives the OpenSpec change 2177-tests-check-error-code-or-match.

Verification

  • Criterion 1: Verified with ast-grep scan that zero bare pytest.raises calls without error verification remain across tests/.
  • Criterion 2: Verified that ast-grep scan fails on a scratch test file containing a bare pytest.raises(ValidationError).
  • Criterion 3: Verified that three changed tests fail when their asserted values are broken (test_invalid_k8s_label_names_rejected, test_http_broker_hook_refuses_a_scheme_other_than_http, test_run_json_subprocess_raises_on_malformed_json_without_default) and pass when restored.
  • Criterion 4: Verified uv run pytest tests/invariants/test_architectural_invariants.py tests/commands/test_net_construct_rules.py passes (149 tests).

Closes #2177

@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
@dan-petty
dan-petty force-pushed the test/2177-tests-check-error-code-or-match branch from 6f9956e to 8ea8765 Compare October 31, 2026 15:09
@dan-petty
dan-petty marked this pull request as ready for review October 31, 2026 15:20
@dan-petty
dan-petty force-pushed the test/2177-tests-check-error-code-or-match branch from 8ea8765 to b6a7fd3 Compare October 31, 2026 15:33
@dan-petty
dan-petty merged commit e2a4eb7 into main Oct 31, 2026
18 checks passed
@dan-petty
dan-petty deleted the test/2177-tests-check-error-code-or-match branch October 31, 2026 15:44
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): each test of an error path checks the error code, the exit code or the message, not only the error type

1 participant