Pin Call Order, Not Just Output, Before Refactoring Legacy Code
Refactors that preserve output can still silently change the sequence of function calls, which fixture-based output comparison cannot detect. The article proposes recording an ordered call trace from the current code before any extraction, committing it as a fixture, and only then refactoring. It uses Python's standard-library sys.settrace to capture calls within the package, recording scalar arguments and redacting sensitive keys. Traces are kept small and cleaned by dropping external frames, noise methods, and moved modules mapped explicitly. A diff tool then surfaces every difference so that each change in call path can be named and reviewed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in