-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
STY: use pytest.raises context syntax #24676
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
pytest.raises(ValueError, Unpacker, read_size=5, max_buffer_size=3) | ||
msg = "read_size should be less or equal to max_buffer_size" | ||
with pytest.raises(ValueError, match=msg): | ||
Unpacker(read_size=5, max_buffer_size=3) |
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 see at least two distinct tests in this one. In the interest of smaller, more modular, testing, let's at least break it up here where I've commented.
@simonjayhawkins : Even though it's just a handful of files, I have to commend the acrobatics you had to do to make this all work. 👍 |
@@ -326,7 +346,8 @@ def test_next(self, mmap_file): | |||
next_line = next(wrapper) | |||
assert next_line.strip() == line.strip() | |||
|
|||
pytest.raises(StopIteration, next, wrapper) | |||
with pytest.raises(StopIteration, match=r'$^'): | |||
next(wrapper) |
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'm surprised r'$^'
works, but it seems it does. In any case, it's a bit confusing to read, because normally the caret (^
) checks for the beginning of a line and the dollar for the end. I'd switch those characters around.
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.
@h-vetinari well spotted. thanks. i'll get that sorted.
Thanks! this could be because either the error messages should be more consistent, or maybe it would have been better to put the expected error messages in the parametrization. The 'acrobatics' would then be scoped to just the variations due to platform/interpreter/compiler. |
thanks @simonjayhawkins |
xref #24332