Skip to content

Instantly share code, notes, and snippets.

@egor83
Created October 25, 2024 10:24
Show Gist options
  • Save egor83/e4ab4ee20d0434d5555805b4a7b07426 to your computer and use it in GitHub Desktop.
Save egor83/e4ab4ee20d0434d5555805b4a7b07426 to your computer and use it in GitHub Desktop.
pytest source problems after running pytests via Docker

I am normally running tests locally against a DB in Docker; I ran tests via Docker once, and since then pytest stopped showing me traceback for the failed tests, only showing > ??? instead.

Running pytest as pytest --vv showed that it tried to find a source code in the wrong path, using path as if it runs inside Docker (even though I was running it locally).

What seems to have happened is the following:

  • running tests via Docker created Python cache (__pycache__/*.pyc) owned by root;
  • re-running tests locally picked up that cached bytecode (either couldn't or didn't try to delete/overwrite it), tried accessing source code with the path hardcoded in cache (that is, with paths as they are in Docker), and failed.

Once I deleted cached files, it started working again.

Thanks to RonnyPfannschmidt for poiting me to the solution here!

Search keywords: triple question marks, three question marks, pytest source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment