Skip to content

TST update test_dist_metrics to use global_random_seed env variable #23453

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

matthewmercuri
Copy link

@matthewmercuri matthewmercuri commented May 25, 2022

Reference Issues/PRs

Addresses #22827 (at least for the one file)

What does this implement/fix? Explain your changes.

This PR simply modifies the tests in test_dist_metrics.py to rely on the env variable rather than the explicit seed set inline.

This is my first PR to the project. Happy to be here! Please let me know if this should be improved in any way.

@ogrisel
Copy link
Member

ogrisel commented May 25, 2022

The environment variable it not meant to be used this way. Please use the global_random_seed pytest fixture as explained in the issue #22827 instead of manually inspecting the environment variables.

Please carefully read the guide lines to update existing test that I wrote in the description of #22827 and also have a look at other merged PRs linked in that issue for examples on how to use the fixture.

You can also have a look at the documentation of the fixture itself to run the fixtured tests locally:

https://scikit-learn.org/dev/computing/parallelism.html#sklearn-tests-global-random-seed

If you want to know more details on how the fixture is coded, please have a look at its source code:

https://github.com/scikit-learn/scikit-learn/blob/main/sklearn/tests/random_seed.py

@matthewmercuri
Copy link
Author

@ogrisel Ah makes sense. I had a feeling, it did not seem idiomatic. I think the difficulty for these tests are that they depend on top-of-scope variables. They are generated without knowledge of theglobal_random_seed fixture. I guess the fix would be to generate those variables (from rng) using the fixture within each test? Otherwise, perhaps we can define another fixture to pass to the tests to make it more DRY?

@ogrisel
Copy link
Member

ogrisel commented May 27, 2022

I think it's fine to have a bit of repetition in this case.

@glemaitre glemaitre removed their request for review December 1, 2022 14:56
@matthewmercuri matthewmercuri deleted the tests/global_random_state_dist_metrics branch January 31, 2023 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants