Skip to content

Conversation

@zhihao11ui
Copy link

Noticed flaky test when run: pytest --flake-finder test_iter.py. This fix addresses an Order-Dependent Brittle (OD-Brit) flaky test caused by reusing an exhausted iterator in multiple function calls. The test failed due to the iterator being consumed after its first use, leading to a StopIteration error on subsequent calls.

The fix recreates fresh iterators before passing them to functions (first() and last()) to ensure the iterator isn't exhausted between uses, and conditional handling was added for non-iterable types (like lists and tuples) to allow direct reuse without exhaustion issues.

This ensures that the tests now run consistently without being affected by the state of the iterators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant