-
-
Notifications
You must be signed in to change notification settings - Fork 11.3k
TST: Replace xunit setup with methods #29616
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
numpy/_core/tests/test_numeric.py
Outdated
@@ -747,27 +747,29 @@ def test_bitwise_xor(self): | |||
|
|||
|
|||
class TestBoolArray: | |||
def setup_method(self): | |||
def _create_arrays(self): |
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.
since we already use pytest wouldn't be better to turn it to a fixture?
also more descriptive names, like bool_arrays
are usually preferred
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.
I can definitely rename it to something more descriptive.
In the tracking issue #29552, we decided that fixtures may not be the best solution. Part of it is them being slightly harder to read compared to these "setup" methods, another part is that fixtures aren't guaranteed to be thread safe. At most, fixtures are only created once per test, so if you run a test on multiple threads, any mutations to the fixture value will be shared between threads.
|
||
def test_logical_and_or_xor(self): | ||
assert_array_equal(self.t | self.t, self.t) |
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.
here as well as in many other tests, there are repeated checks with slightly different data
i think that more standard way would be to use fixtures:
@pytest.mark.parametrize("op,a,b,expected", [
(lambda x, y: x | y, t, t, t),
(lambda x, y: x | y, f, f, f),
(lambda x, y: x | y, t, f, t),
# ...
])
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.
I think this would be fine to do but is orthogonal to what Britney is working on so isn't necessary to merge this
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.
Looks good, thanks @bwhitt7!
This PR is related to #29552, with this being the third PR. 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 in numpy/_core.
test_overrides.py includes unittest.mock.Mock, a thread-unsafe functionality that is caught by pytest-run-parallel, so it is not completely thread-safe yet, but all of its setup methods have been replaced.