TST: Replace xunit setup with methods #29666
Open
+213
−174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.