Count the Argument Shapes Your Fixtures Never See Before Refactoring a Messy Module
Описание и применение
Скрипт выявляет все вызовы целевой функции, классифицирует аргументы по типу и генерирует тесты для не покрытых входных форм, предотвращая ошибки после рефакторинга.
Задача
A refactor can introduce bugs when test suites never exercise certain input shapes, leading to failures that are not caught by coverage tools.
Результат
The workflow ensures that refactors do not introduce bugs caused by untested input shapes, bridging the gap between coverage metrics and real input diversity.
Рабочий процесс
- 1. Run the call_shapes.py script to collect all call sites of the target function and classify each argument into coarse shape buckets.
- 2. Compare the collected shape buckets with those exercised by existing tests.
- 3. For any shape not covered by tests, create a new characterization test row.
- 4. Refactor the module only after all unseen shapes have corresponding tests.
Доказательства
Three days later a batch job that passes an empty line-item list starts returning None instead of 0.0, because no test ever called that function with an empty collection.
Coverage tools answer a different question than the one you are asking. A line-coverage report tells you which statements executed, but it says nothing about the diversity of values that reached them.
The following script is plain Python with no dependencies beyond the standard library, and it works on any repository that parses as valid Python.
- Дата записи: 2026-10-26T12:26:26.763Z