Skip to content
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

[flake8-pytest-style] Implement pytest.warns diagnostics (PT029, PT030, PT031) #15444

Merged
merged 4 commits into from
Jan 13, 2025

Conversation

tjkuson
Copy link
Contributor

@tjkuson tjkuson commented Jan 12, 2025

Summary

Implements upstream diagnostics PT029, PT030, PT031 that function as pytest.warns corollaries of PT010, PT011, PT012 respectively. Most of the implementation and documentation is designed to mirror those existing diagnostics.

Closes #14239

Test Plan

Tests for PT029, PT030, PT031 largely copied from PT010, PT011, PT012 respectively.

cargo nextest run

Copy link
Contributor

github-actions bot commented Jan 12, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+182 -0 violations, +0 -0 fixes in 8 projects; 47 projects unchanged)

DisnakeDev/disnake (+4 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ tests/ext/commands/test_params.py:119:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/test_embeds.py:473:23: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/test_embeds.py:475:23: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/test_embeds.py:477:23: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning

PlasmaPy/PlasmaPy (+38 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ tests/analysis/swept_langmuir/test_floating_potential.py:213:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/analysis/test_fit_functions.py:530:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/diagnostics/charged_particle_radiography/test_synthetic_radiography.py:372:5: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_collisions_dimensionless.py:133:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_collisions_frequencies.py:727:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_collisions_lengths.py:207:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_collisions_misc.py:152:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_coulomb.py:134:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_coulomb.py:160:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/formulary/collisions/test_coulomb.py:97:9: PT031 `pytest.warns()` block should contain a single simple statement
... 28 additional changes omitted for project

apache/airflow (+37 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ providers/tests/amazon/aws/utils/test_connection_wrapper.py:121:9: PT031 `pytest.warns()` block should contain a single simple statement
+ providers/tests/celery/executors/test_celery_executor.py:259:31: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
+ providers/tests/cncf/kubernetes/executors/test_kubernetes_executor.py:1269:27: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
+ providers/tests/google/cloud/hooks/vertex_ai/test_generative_model.py:153:9: PT031 `pytest.warns()` block should contain a single simple statement
+ providers/tests/google/cloud/hooks/vertex_ai/test_generative_model.py:168:9: PT031 `pytest.warns()` block should contain a single simple statement
+ providers/tests/google/cloud/hooks/vertex_ai/test_generative_model.py:179:9: PT031 `pytest.warns()` block should contain a single simple statement
+ providers/tests/google/cloud/hooks/vertex_ai/test_generative_model.py:193:9: PT031 `pytest.warns()` block should contain a single simple statement
+ providers/tests/google/cloud/hooks/vertex_ai/test_generative_model.py:208:9: PT031 `pytest.warns()` block should contain a single simple statement
... 24 additional changes omitted for rule PT031
+ task_sdk/tests/defintions/test_asset.py:117:23: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ task_sdk/tests/defintions/test_baseoperator.py:242:27: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
... 27 additional changes omitted for project

bokeh/bokeh (+20 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

+ tests/unit/bokeh/models/test_formatters.py:35:5: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/unit/bokeh/models/test_plots.py:81:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/unit/bokeh/models/test_plots.py:81:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/unit/bokeh/models/test_sources.py:283:9: PT031 `pytest.warns()` block should contain a single simple statement
+ tests/unit/bokeh/models/test_sources.py:765:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/unit/bokeh/models/test_sources.py:771:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/unit/bokeh/models/test_sources.py:777:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/unit/bokeh/models/test_sources.py:783:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ tests/unit/bokeh/plotting/test_graph.py:122:23: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
... 6 additional changes omitted for rule PT030
+ tests/unit/bokeh/plotting/test_graph.py:122:5: PT031 `pytest.warns()` block should contain a single simple statement
... 10 additional changes omitted for project

pandas-dev/pandas (+1 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ pandas/tests/copy_view/test_chained_assignment_deprecation.py:20:10: PT029 Set the expected warning in `pytest.warns()`

pypa/setuptools (+3 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ pkg_resources/tests/test_resources.py:864:9: PT031 `pytest.warns()` block should contain a single simple statement
+ setuptools/tests/config/test_pyprojecttoml_dynamic_deps.py:106:5: PT031 `pytest.warns()` block should contain a single simple statement
+ setuptools/tests/test_build_py.py:168:5: PT031 `pytest.warns()` block should contain a single simple statement

python-trio/trio (+9 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ src/trio/_core/_tests/test_asyncgen.py:45:9: PT031 `pytest.warns()` block should contain a single simple statement
+ src/trio/_core/_tests/test_guest_mode.py:421:5: PT031 `pytest.warns()` block should contain a single simple statement
+ src/trio/_tests/test_deprecate.py:273:23: PT030 `pytest.warns(DeprecationWarning)` is too broad, set the `match` parameter or use a more specific warning
+ src/trio/_tests/test_dtls.py:752:5: PT031 `pytest.warns()` block should contain a single simple statement
+ src/trio/_tests/test_dtls.py:768:5: PT031 `pytest.warns()` block should contain a single simple statement
+ src/trio/_tests/test_dtls.py:791:5: PT031 `pytest.warns()` block should contain a single simple statement
+ src/trio/_tests/test_dtls.py:808:5: PT031 `pytest.warns()` block should contain a single simple statement
... 3 additional changes omitted for rule PT031

astropy/astropy (+70 -0 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview

+ astropy/config/tests/test_configs.py:500:9: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/config/tests/test_configs.py:540:9: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/convolution/tests/test_convolve.py:1259:5: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/convolution/tests/test_convolve_fft.py:812:9: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/coordinates/tests/test_sky_coord.py:1860:5: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/coordinates/tests/test_velocity_corrs.py:293:23: PT030 `pytest.warns(Warning)` is too broad, set the `match` parameter or use a more specific warning
+ astropy/cosmology/funcs/tests/test_funcs.py:270:9: PT031 `pytest.warns()` block should contain a single simple statement
+ astropy/io/ascii/tests/test_c_reader.py:1175:15: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/ascii/tests/test_c_reader.py:1281:15: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/ascii/tests/test_c_reader.py:1288:19: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/ascii/tests/test_c_reader.py:1352:10: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/ascii/tests/test_c_reader.py:1363:10: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/ascii/tests/test_ipac_definitions.py:101:5: PT031 `pytest.warns()` block should contain a single simple statement
... 50 additional changes omitted for rule PT031
+ astropy/io/ascii/tests/test_qdp.py:222:23: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ astropy/io/fits/hdu/compressed/tests/test_compressed.py:501:31: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ astropy/io/fits/hdu/compressed/tests/test_compressed.py:513:18: PT029 Set the expected warning in `pytest.warns()`
+ astropy/io/fits/tests/test_header.py:195:22: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ astropy/table/tests/test_table.py:2325:27: PT030 `pytest.warns(UserWarning)` is too broad, set the `match` parameter or use a more specific warning
+ astropy/wcs/tests/test_profiling.py:72:10: PT029 Set the expected warning in `pytest.warns()`
... 2 additional changes omitted for rule PT029
... 51 additional changes omitted for project

Changes by rule (3 rules affected)

code total + violation - violation + fix - fix
PT031 144 144 0 0 0
PT030 28 28 0 0 0
PT029 10 10 0 0 0

@tjkuson tjkuson marked this pull request as ready for review January 12, 2025 20:58
Copy link
Member

@charliermarsh charliermarsh left a comment

Choose a reason for hiding this comment

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

This looks great, thanks.

@charliermarsh charliermarsh self-assigned this Jan 13, 2025
@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Jan 13, 2025
@charliermarsh charliermarsh enabled auto-merge (squash) January 13, 2025 01:42
/// with pytest.warns(MyWarning):
/// setup()
/// func_to_test() # not executed if `setup()` triggers `MyWarning`
/// assert foo() # not executed
Copy link
Member

Choose a reason for hiding this comment

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

I couldn't figure out from the docs... Is this true? Does the block stop as soon as the warning is triggered? Or is this a copy-paste error from the raises variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That comment was a copy error, apologies!

Copy link
Member

Choose a reason for hiding this comment

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

Are you able to PR a revision to the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On it!

@charliermarsh charliermarsh merged commit 347ab5b into astral-sh:main Jan 13, 2025
20 checks passed
@tjkuson tjkuson deleted the pytest-raises branch January 13, 2025 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend pytest-raises-with-multiple-statements (PT012) to cover pytest.warns
2 participants