fix: validate the --contexts regexes up front - #2262
Conversation
An invalid regex went straight to the SQLite REGEXP user function, so the failure surfaced as a DataError blaming the data file. Every other regex-valued setting is already validated via process_regexlist.
|
Can you tell me what you mean by "the mutation check"? |
|
Sorry, that was jargon on my part. I just mean I checked that the new test actually fails when the fix is removed, instead of assuming it does. Concretely, I deleted only these five lines from for context in contexts:
try:
re.compile(context)
except re.error as e:
raise ConfigError(f"Invalid context regex {context!r}: {e}") from eand re-ran the test. It fails, and it fails with the original symptom rather than a message mismatch: Then I put the lines back and it passes again. I re-ran both just now to make sure I was quoting you the real output. The reason I bother: I have written tests before that passed no matter what the source did, so the test proved nothing. Reverting the source and confirming the specific test goes red is the cheapest way to catch that. Reverting the whole change is weaker, since it can fail for an unrelated reason like an unused import. |
|
Thanks, I do the same thing to confirm that my tests are correct. |
|
This is now released as part of coverage 7.16.0. |
An invalid regex in
--contextsreports a confusing error that blames the data file.After:
The data file is fine. The regex goes straight to the SQLite
REGEXPuser function, wherere.searchraises inside sqlite, and sqlite reports only that some user function failed. Same forcoverage json --contexts=,coverage html --contexts=, the[report] contextsconfig setting, andCoverage.report(contexts=[...]).The fix
process_regexlistinconfig.pyalready does exactly this for every other regex-valued setting:contextsis the one that never got it, because it is not compiled at config time, it is handed to sqlite later. So the same check runs inset_query_contexts, which is the point every entry path funnels through.Testing
test_set_query_contexts_bad_regexintests/test_data.py.Removing only the validation loop fails it, and the failure is the original symptom rather than a message mismatch:
pytest tests/test_data.pyis 4 passed for the selected tests.Pre-existing failures
The full suite is
143 failed, 1450 passed, 23 skipped, 14 errorson a clean checkout here, and143 failed, 1451 passed, 23 skipped, 14 errorswith this change. A diff of the sorted FAILED lists is empty, so every one of those is pre-existing in this environment, which has no C extension built and lacks the venv/subprocess test dependencies.Disclosure: written with AI assistance (Claude Code). I reproduced the confusing error at the CLI, checked all four entry paths, confirmed the pre-existing failures by diffing against a stashed tree, and ran the mutation check myself.