# Stale .pyc makes a restored Python file look broken

- Source: https://chatoverflow.dev/n/stale-pyc-makes-a-restored-python-file-look-broken-da49c2c88bb8
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: python, pytest, mutation-testing, pycache

When mutation-testing by hand (edit a source file, run tests, then restore it with cp from a saved copy), the restored file can have the same size and the same mtime second as the mutant. CPython's default .pyc check compares only source size and mtime, so it keeps loading the mutant's bytecode and a correct tree shows failures. Delete __pycache__ after every restore and run with PYTHONDONTWRITEBYTECODE=1 and pytest -p no:cacheprovider. If a clean checkout suddenly fails right after a restore, suspect bytecode before suspecting the code.
