8000 MAINT: pytest cleanups · Pull Request #10294 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

MAINT: pytest cleanups #10294

New issue

Have a question about thi 8000 s 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

Merged
merged 2 commits into from Jan 9, 2018
Merged

MAINT: pytest cleanups #10294

merged 2 commits into from Jan 9, 2018

Conversation

ghost
Copy link
@ghost ghost commented Dec 29, 2017

No description provided.

@@ -94,7 +94,7 @@ def test_overlapping_assignments():
srcidx = tuple([a[0] for a in ind])
dstidx = tuple([a[1] for a in ind])

yield _check_assignment, srcidx, dstidx
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the parameterize decorator here instead?

Copy link
Author

Choose a reason for hiding this comment

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

Tried that; doesn't work with nose. I can drop the second commit if you want, but a similar PR was merged previously.

Copy link
Member

Choose a reason for hiding this comment

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

Good point, I guess this is fine. Deprecating this style of test feels like a step backwards to me, but that's beyond our control.

Copy link
Member

Choose a reason for hiding this comment

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

I added limited support for parameters on nose in nose_tools just for some of these cases. It doesn't have the full capabilities of the pytest version, however.

Copy link
Author

Choose a reason for hiding this comment

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

Correct. parametrize doesn't even replace yield because it must be static on collection. I looked at other examples and the same thing was done as here. Complain to the pytest folks if you want.

@eric-wieser
Copy link
Member

Just for the sake of linking, second commit is fallout from pytest-dev/pytest#1714

raise ValueError('Function did not raise an exception')

return assert_raises_context()
return pytest.raises(exception_class)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe pass on kwargs too?

Copy link
Author

Choose a reason for hiding this comment

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

Look at what it's replacing: no kwargs are present. The documentation specifies that there should be no kwargs when fn is none.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member
@eric-wieser eric-wieser Dec 29, 2017

Choose a reason for hiding this comment

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

Right, the documentation specifies that they must not be passed, but the implementation just silently drops them if they are. Forwarding them would probably cause pytest to throw an appropriate error, although an elif kwargs: raise TypeError would do that job too.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe I could simply remove the branch, though I seem to recall that previously failed.



def test_read_version_1_0_bad_magic():
for magic in bad_version_magic + malformed_magic:
f = BytesIO(magic)
yield raises(ValueError)(format.read_array), f
raises(ValueError)(format.read_array)(f)
Copy link
Member

Choose a reason for hiding this comment

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

No value in using the raises decorator here now that it's not a yield test - just use assert_raises

@@ -728,13 +728,15 @@ def test_read_magic():
def test_read_magic_bad_magic():
for magic in malformed_magic:
f = BytesIO(magic)
yield raises(ValueError)(format.read_magic), f
with assert_raises(ValueError):
format.read_array(f)
Copy link
Member

Choose a reason for hiding this comment

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

Convention seems to be to use the shorter assert_raises(ValueError, format.read_array, f) in almost all our test cases

Copy link
Member
@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

One stylistic nit, but otherwise looks fine

@eric-wieser eric-wieser merged commit 3d2205d into numpy:master Jan 9, 2018
@eric-wieser
Copy link
Member

Thanks @xoviat!

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
0