I have a test case for an algorithm, which gives a different result after the first execution.
The test imports the algorithm and the test data from two files.
The first execution returns the correct results and creates a .pyc file for the test data file. The second and all following executions return incorrect results. When I delete the test data's .pyc file the next execution returns the correct results again (and creates a new .pyc file again).
When I move the test data into the same file as the test case itself (i.e. avoiding the creation of a .pyc file) the test always passes.
I cannot apply this fix to my full program.
Is this a known issue, is there a fix?
.pyc files contain byte code, which is what the Python interpreter compiles the source to. This code is then executed by Python's virtual machine.
Python's documentation explains the definition like this:
The .pyc files are created (and possibly overwritten) only when that python file is imported by some other script. If the import is called, Python checks to see if the .pyc file's internal timestamp matches the corresponding .py file. If it does, it loads the .pyc; if it does not or if the .pyc does not yet exist, Python compiles the .py file into a .pyc and loads it.