Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Fix appending to .coverage if exec ends in non-existent directory #806
For example, with the following file,
import tempfile import os with tempfile.TemporaryDirectory() as tmpdir: os.chdir(tmpdir)
Run coverage on this as follows:
This results in a
This patch avoids this problem by ensuring that we return to a known directory (the original directory we ran in) once the
One could argue that it is the exec'd script's responsibility for ensuring that it doesn't end in an invalid directory, but it seems reasonable for
I believe this issue also warrants a unit test, but I couldn't make out the right way to do this after a perusal of the test suite. Please feel free to add a test or to guide me to a good example for how to implement it. Thank you!
If the file that is exec'd chdirs to a directory that doesn't exist at the end of the execution, then we will fail to connect to the SQLite database (due to a failing `os.getcwd` command). We can easily fix this if we ensure we are in a directory that exists after executing the foreign code. Returning to the original directory seems to be a sensible choice.
@@ Coverage Diff @@ ## master #806 +/- ## ========================================= - Coverage 90.65% 90.6% -0.05% ========================================= Files 81 81 Lines 11178 11180 +2 Branches 1150 1150 ========================================= - Hits 10133 10130 -3 - Misses 936 938 +2 - Partials 109 112 +3