Skip to content

Conversation

bwhitt7
Copy link
Contributor

@bwhitt7 bwhitt7 commented Sep 3, 2025

This PR is related to #29552. This PR has the goal of making NumPy's testing suite more thread safe. This introduces changes to the setup methods for 2 more testing files, 1 in numpy/_core and 1 in numpy/testing. Pytest's classic xunit setup and teardown methods are thread unsafe, typically not running before the tests do, leading to AttributionErrors. This PR changes these setup method to basic "creation" methods that are called within the tests that need them, or for test_utils, creating class methods that are overridden when needed.

Notability, this PR introduces changes to RNG in the test suite. np.random.seed is thread-unsafe, so utilizing the new Generator will give us thead-safe RNG. In tests where the results of the RNG is important (such as tests under TestDot in test_multiarray.py), we can instead use RandomState, which is a thread safe implementation of the legacy random generator. Eventually it'll probably be a good idea to rewrite these tests with the new default RNG.

Both files still have some thread-unsafe functionality, such as the usage of temporary files in test_multiarray.py.

Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple comments. The change to test_utils makes sense, seems like the most straightforward way to avoid the xunit setups in those.

@bwhitt7
Copy link
Contributor Author

bwhitt7 commented Sep 4, 2025

@ngoldbaum Made the changes.

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.

2 participants