-
-
Notifications
You must be signed in to change notification settings - Fork 25.8k
MAINT Remove some unwanted side effects in our test suite #29584
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
Conversation
So indeed this does trigger failures that look similar to what I observe locally with my non-voluntarily randomized pytest command:
Let me re-trigger the CI with a different ordering to check if the list of failures is stable or not. |
Here are the failing tests for the second random ordering of the tests:
So indeed the list of failures depend on the execution order of the tests which reveals unintended side effects in our test suite. |
Those test files share in common the fact that they define a test dataset at important time (as test module attributes) and then reuse them multiple times while sometimes modifying them inplace (as is the case in I did a minimal fix for the |
…ests.test_roc_curve_display
…reeRegressor] [azure parallel]
All tests pass locally for me now. I cannot reproduce the last failure: _ test_regression_tree_missing_values_toy[squared_error-X3-ExtraTreeRegressor] _
[gw0] darwin -- Python 3.12.5 /usr/local/miniconda/envs/testvenv/bin/python
Tree = <class 'sklearn.tree._classes.ExtraTreeRegressor'>
X = array([[ 1.],
[ 2.],
[ 3.],
[nan],
[ 6.],
[nan]])
criterion = 'squared_error'
@pytest.mark.parametrize("Tree", [DecisionTreeRegressor, ExtraTreeRegressor])
@pytest.mark.parametrize(
"X",
[
# missing values will go left for greedy splits
np.array([np.nan, 2, np.nan, 4, 5, 6]),
np.array([np.nan, np.nan, 3, 4, 5, 6]),
# missing values will go right for greedy splits
criterion = 'squared_error'
tree = ExtraTreeRegressor(random_state=0)
tree_ref = ExtraTreeRegressor(random_state=0)
y = array([0, 1, 2, 3, 4, 5]) I really do not understand what causes this and why it would be related to test ordering. This test creates new estimator instances each time and the data should not be modified. |
With the extra debugging info in the assertion we get both for the impurity = tree.tree_.impurity
> assert all(impurity >= 0), impurity.min() # MSE should always be positive
E AssertionError: -12.25 So this is definitely above the rounding error level... Let me try to push a new build with a different ordering seed. |
…_error-X3-ExtraTreeRegressor] with a different random order seed [azure parallel]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, the CI no longer reproduces the last reported unsolved failure.
Let's remove the test ordering shuffling to be able to merge the fixes for the unwanted test side effects.
Assuming CI stays green after the last commit, this should be ready for review @glemaitre and @lesteve. |
In case it is ever needed in the future, this is the kind of thing that was used in the CI to reproduce the failures (reverted in dd4ca3c):
|
Merging, thanks! |
I have observed that my local pytest runs test in a random order locally with recent Python versions and I suspect that this is causing a few failures that are not reproduced on the CI.
Let's try to reproduce this on the CI with a few runs with different seeds in this draft PR with the
pytest-random-order
plugin.EDIT: removing side-effects is also useful for running the tests in parallel with threads, e.g. for #30007.