Skip to content

TST: test for warnings using pytest.warns() #56974

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

Merged
merged 2 commits into from
Jan 23, 2024

Conversation

mgorny
Copy link
Contributor

@mgorny mgorny commented Jan 20, 2024

Fix tests that used pytest.raises() to check for warnings, to use pytest.warns() instead. This is more correct, and it fixes running the test suite without -Werror. This is how Gentoo runs it, to avoid sudden test failures due to new deprecation warnings from upgraded dependencies.

@@ -194,7 +194,7 @@ def test_to_offset_lowercase_frequency_deprecated(freq_depr):
depr_msg = f"'{freq_depr[1:]}' is deprecated and will be removed in a "
f"future version, please use '{freq_depr.upper()[1:]}' instead."

with pytest.raises(FutureWarning, match=depr_msg):
with pytest.warns(FutureWarning, match=depr_msg):
Copy link
Member

Choose a reason for hiding this comment

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

Please use tm.assert_produces_warning (and below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@mroeschke mroeschke added the Testing pandas testing functions or related to the test suite label Jan 23, 2024
Fix tests that used `pytest.raises()` to check for warnings, to use
`tm.assert_produces_warning()` instead.  This is more correct, and it
fixes running the test suite without `-Werror`.  This is how Gentoo runs
it, to avoid sudden test failures due to new deprecation warnings from
upgraded dependencies.
@mroeschke
Copy link
Member

pre-commit.ci autofix

@mroeschke mroeschke added this to the 3.0 milestone Jan 23, 2024
@mroeschke mroeschke merged commit 85b7445 into pandas-dev:main Jan 23, 2024
@mroeschke
Copy link
Member

Thanks @mgorny

@mgorny
Copy link
Contributor Author

mgorny commented Jan 23, 2024

Thanks! And sorry for not running pre-commit in the morning, as I've updated the PR just before going out.

pmhatre1 pushed a commit to pmhatre1/pandas-pmhatre1 that referenced this pull request May 7, 2024
* TST: test for warnings using tm.assert_produces_warning()

Fix tests that used `pytest.raises()` to check for warnings, to use
`tm.assert_produces_warning()` instead.  This is more correct, and it
fixes running the test suite without `-Werror`.  This is how Gentoo runs
it, to avoid sudden test failures due to new deprecation warnings from
upgraded dependencies.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

CLN: Use assert_produces_warning instead of pytest.raises to show FutureWarning
2 participants