-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Avoid bare pytest.raises in dtypes/test_dtypes.py #32672
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
Avoid bare pytest.raises in dtypes/test_dtypes.py #32672
Conversation
Found a type-o in one of the error messages and corrected it.
� Conflicts: � pandas/tests/dtypes/test_dtypes.py
They got undone due to new commits to pandas.
Found a type-o in one of the error messages and corrected it.
They got undone due to new commits to pandas.
…s_test_dtypes_2' into 30999_disallow_bare_pytest_raises_test_dtypes
Please be aware that I changed the dtypes.py file. I believe that there's a spelling mistake in one of the error messages. Could someone please confirm whether this is the case? Please note that one of the other testing files uses the other verbiage. It's the difference between Categorical and Categorial. |
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.
Thanks @Vlek for the PR. Categorial -> Categorical is fine but need to fix failing tests. (test_constructor_with_null and test_from_codes_nan_cat_included)
pandas/tests/dtypes/test_dtypes.py
Outdated
@@ -414,16 +414,17 @@ def test_construction_from_string(self, dtype): | |||
assert is_dtype_equal(dtype, result) | |||
result = PeriodDtype.construct_from_string("period[D]") | |||
assert is_dtype_equal(dtype, result) | |||
with pytest.raises(TypeError): | |||
msg = "Cannot construct a 'PeriodDtype' from " |
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.
This error message is raised by pandas itself. In these cases, we would want to check the complete message.
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.
The reason I left it out is because it's just repeating the input that we're giving it. If that's the case, then could I create a list of all of the strings and then for-loop through them? I don't know how much I should be changing the tests to add these messages so I was hesitant to go too far.
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.
if you can split and parametrize this tests could then do something like .. msg = f"Cannot construct a 'PeriodDtype' from '{string}'"
for guidance checkout test_construction_from_string tests for IntervalDtype (test_construction_from_string_errors) and DatetimeTZDtype (test_construct_from_string_invalid_raises) that have already been split and parametrized.
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.
Understood, I added them using what you gave as a template. I also fixed the other two tests, everything passes.
Co-Authored-By: Simon Hawkins <[email protected]>
given by simonjayhawkins.
…://github.com/Vlek/pandas into 30999_disallow_bare_pytest_raises_test_dtypes
…999_disallow_bare_pytest_raises_test_dtypes
Thanks @Vlek |
Avoid bare pytest.raises in dtypes/test_dtypes.py (pandas-dev#32672)
ref [Good first issue] TST: Disallow bare pytest.raises #30999
tests added / passed
passes
black pandas
passes
git diff upstream/master -u -- "*.py" | flake8 --diff