-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix flaky test on test_dictionary.py::test_dictionary_looping #2105
base: main
Are you sure you want to change the base?
Conversation
should I re-formate the code with the format requirements of codespell and submit a new PR? |
I assume you've not had this test fail on a single run, so it's not flaky in the traditional sense but it's not compatible with re-running the test multiple times in the same session? I'm not targeting this at you, but this fix seems like quite a bodge to me, isn't there some set up and tear down functions for the test (rather than the test suite) which we could deal with this in? Flaky ( https://github.com/box/flaky ) seems to support this stuff, based on issues like ( box/flaky#124 box/flaky#109 box/flaky#53 box/flaky#39 ). Maybe pytest-flakefinder does too and we just need to add setup/tearDown or add these to it?
You can just fix it in this PR if you'd prefer. |
update the test file
Thank you for reply my PR! I'm a master's student that trying to fix flaky tests as a course project. In the definition, a flaky test means a test could produce different results with the testing code unchanged. In our case, when a testing function fail when re-run multiple times in the same session is considered flaky.
So the general tear down/fixture does not really fit for That is why I used a counter for the looping times in a fixture so I could clean at the right time. In re-runs, using |
This PR aims to fix the flaky test on test_dictionary.py::test_dictionary_looping so the test could pass for multiple test runs
The result
The test can pass when running only once, but fail when running the test suit multiple times. When asserting the key pair does not exist on the
global_err_dicts
orglobal_pairs
, the pair actually exists start on the second test run.Steps to reproduce the issue
pip install pytest-flakefinder
pytest -k test_dictionary.py --flake-finder
Issue of the code
The reason is the code tried to assert the key pair or error read from the file doesn't exist. However, the
global_err_dicts
andglobal_pairs
only initialize once per pytest runs, so start from the second run oftest_dictionary_looping
, the assert will fail.Proposed solution
Adding a variable to track how many txt files we had read. With a pytest fixture to initialize both global_err_dicts
and
global_pairs` if the variable indicates it is a new test run.