DEV Community

TildAlice
TildAlice

Posted on • Originally published at tildalice.io

Import Side Effects Break Tests: 4 Patterns That Pass Locally

The Test That Passed on My Laptop But Failed in CI

Your test suite runs green locally. You push to CI. The build fails with AttributeError: module 'app.config' has no attribute 'DATABASE_URL'. You run the exact same test locally again — still passes. This isn't a flaky test or a race condition. It's an import side effect, and it only shows up when test execution order changes.

Import side effects are code that runs at module import time and modifies global state. In development, you usually import modules in the same order every time. Your IDE loads them, your manual test runs load them, and everything works. But test runners like pytest shuffle test collection order, run tests in parallel, or isolate imports per test. Suddenly, the code that worked fine during development explodes.

I'm going to walk through four real patterns I've debugged where import side effects caused test failures that were invisible in local development. Each one has a specific symptom, a root cause, and a fix.

A detailed image of a reticulated python showcasing its patterned scales and intricate skin texture.

Photo by Erdal Erdal on Pexels

Continue reading the full article on TildAlice

Top comments (0)