Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Multiple tests inside
test_mdutils.py
were found to be flaky, i.e. tests that both pass and fail despite no changes to the code or the tests itself.Using the pytest-flakefinder plugin, when the tests were re-run more than once, multiple tests inside
test_mdutils.py
were failing. Upon looking at the code, the reason was because the working directory was being changed due to the various calls toos.chdir(tmp)
insidetest_fileutils.py
. This meant the tests could not locateTest_file.md
in the directory they were meant to be in.To fix this, I just removed the calls to
os.chdir(tmp)
intest_fileutils.py
and modifiedMarkDownFile
insidefileutils.py
to include another parameter calledtmp
, which indicates whether or not the markdown file should be created in the temporary directory or not. If this is not empty, the code is modified in such a way that the temporary files are created in the temporary directory without calls toos.chdir(tmp)
. This is done by including the entire path that the file is supposed to be in.To reproduce:
pytest-flakefinder
by following the instructions here.pytest --flake-finder tests
After implementing the fix, all tests pass successfully, both with and without the pytest-flakefinder plugin being used.
In general, flaky tests are a pain to fix with regards to locating the root of the actual problem, so it's a good idea to fix them when you detect them. I'm aware that the tests might not be re-run at all, but this change makes the entire module more robust and future-proof so it's just a small fix for you to consider.