apache / airflow

Apache Airflow - A platform to programmatically author, schedule, and monitor workflows
https://airflow.apache.org/
Apache License 2.0
36.32k stars 14.09k forks source link

Fix remaining `PT012` pytest checks: `pytest-raises-with-multiple-statements` #38270

Closed Taragolis closed 5 months ago

Taragolis commented 6 months ago

Body

Follow-up task for https://github.com/apache/airflow/pull/38219

We enable this rule for avoid accidentally misses some asserts into the pytest.raises() blocks

Easy way to find all linting problem into the module

  1. Remove corresponding line to particular module into the pyproject.toml in [tool.ruff.lint.per-file-ignores]
  2. Run ruff via pre-commit hook
  3. Run tests locally
❯ pre-commit run ruff --all-files

Run 'ruff' for extremely fast Python linting.............................Failed
- hook id: ruff
- exit code: 1

tests/providers/amazon/aws/hooks/test_base_aws.py:1126:5: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/hooks/test_datasync.py:410:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/hooks/test_eks.py:792:13: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/hooks/test_redshift_data.py:80:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/hooks/test_s3.py:495:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/operators/test_emr_serverless.py:435:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/operators/test_redshift_data.py:300:9: PT012 `pytest.raises()` block should contain a single simple statement
Found 7 errors.
tests/providers/amazon/aws/sensors/test_glacier.py:91:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/sensors/test_glue.py:129:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/sensors/test_lambda_function.py:100:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/system/utils/test_helpers.py:88:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/system/utils/test_helpers.py:125:13: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/transfers/test_redshift_to_s3.py:377:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/triggers/test_ecs.py:55:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/triggers/test_ecs.py:74:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/waiters/test_neptune.py:56:9: PT012 `pytest.raises()` block should contain a single simple statement
tests/providers/amazon/aws/waiters/test_neptune.py:77:9: PT012 `pytest.raises()` block should contain a single simple statement
Found 10 errors.

[!TIP] Feel free to ask a suggestion/helps in slack channels #contributors or #new-contributors

[!NOTE] There is no problem to mark specific case which cannot be easily resolved by add # noqa: PT012 reason why it should be skiped from check

[!WARNING] There is a chance to found a regression into the Providers Code Base, so better fix it separately of other changes. E.g fix regression in code base and adopt the test by the separate PR

Regular Unit Tests

Provider amazon

Provider apache.beam

Provider apache.hive

Provider apache.spark

Provider celery

Provider cncf.kubernetes

Provider common.sql

Provider databricks

Provider datadog

Provider dbt

Provider fab

Provider ftp

Provider google

Provider jenkins

Provider microsoft.azure

Provider microsoft.psrp

Provider openai

Provider oracle

Provider papermill

Provider sftp

Provider ssh

Provider telegram

K8S Tests

For more detail have a look Kubernetes tests into the contributors documentation

https://github.com/apache/airflow/blob/5a612dac4a6ebdf44d73d5d23fed5419e2519eb1/pyproject.toml#L1406

Committer

shahar1 commented 5 months ago

And we're done :) Good job everyone!

potiuk commented 5 months ago

Cool!