Skip to content

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

Conversation

Vlek
Copy link
Contributor

@Vlek Vlek commented Mar 13, 2020

Derek McCammond added 6 commits March 10, 2020 21:05
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
@Vlek
Copy link
Contributor Author

Vlek commented Mar 13, 2020

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.

@simonjayhawkins simonjayhawkins added the Testing pandas testing functions or related to the test suite label Mar 13, 2020
@simonjayhawkins simonjayhawkins added this to the 1.1 milestone Mar 13, 2020
Copy link
Member

@simonjayhawkins simonjayhawkins left a 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)

@@ -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 "
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

@simonjayhawkins simonjayhawkins merged commit 19624de into pandas-dev:master Mar 18, 2020
@simonjayhawkins
Copy link
Member

Thanks @Vlek

sthagen added a commit to sthagen/pandas-dev-pandas that referenced this pull request Mar 18, 2020
Avoid bare pytest.raises in dtypes/test_dtypes.py (pandas-dev#32672)
@Vlek Vlek deleted the 30999_disallow_bare_pytest_raises_test_dtypes branch March 21, 2020 00:41
SeeminSyed pushed a commit to CSCD01-team01/pandas that referenced this pull request Mar 22, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 23, 2020
jbrockmendel pushed a commit to jbrockmendel/pandas that referenced this pull request Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing pandas testing functions or related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants