Fix brittle flaky tests in core/test_io.py #243
Closed
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.
Four of the tests inside the
fooof/tests/core/test_io.py
module were found to be flaky (specifically, something called brittle flakiness), when using the pytest-flakefinder plugin. A flaky test is a test that both passes and fails despite no changes to the code or the test itself. Brittle flakiness (defined as per iFixFlakies) is when a test runs fine when run in conjunction with the other tests in the same module but fails when run on its own.To reproduce:
pytest fooof/tests/core/test_io.py::test_load_json_str
pytest fooof/tests/core/test_io.py::test_load_json_fobj
pytest fooof/tests/core/test_io.py::test_load_jsonlines
pytest fooof/tests/core/test_io.py::test_load_file_contents
All other tests inside
test_io.py
ran fine when run on their own. But when the tests above were run on their own, they failed, due to some files not existing. When the entire module is run, this behavior is not seen. To fix, I just added the appropriate function calls which creates the JSON files required by the tests above.I'm aware that the tests might not be run on their own, but this makes the entire module more robust so it's just a small fix for you to consider.
NOTE: This PR contains similar changes to my previously opened PR. The difference is that the tests in this PR were from a different module and were found at a later time.