You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Taragolis (via GitHub)" <gi...@apache.org> on 2024/03/16 20:26:09 UTC
[PR] Partially enable PT012 rule [airflow]
Taragolis opened a new pull request, #38219:
URL: https://github.com/apache/airflow/pull/38219
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
Original I've personally thought that this rule controversial and useless, however It solve non obvious mistakes which could be very easy miss during review
Simple sample what this PR intends to solve
```python
def test_sample():
with pytest.raises(NotImplementedError):
raise NotImplementedError()
assert 1 == 2 # This code unreachable
```
Not all test cases could be easily change, but most of them. In this PR only Core tests are changed
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on code in PR #38219:
URL: https://github.com/apache/airflow/pull/38219#discussion_r1527533612
##########
tests/cli/test_cli_parser.py:
##########
@@ -229,6 +229,7 @@ def test_positive_int(self):
with pytest.raises(argparse.ArgumentTypeError):
cli_config.positive_int(allow_zero=False)("0")
+ with pytest.raises(argparse.ArgumentTypeError):
Review Comment:
Agree. Let's have it in.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #38219:
URL: https://github.com/apache/airflow/pull/38219#discussion_r1527251417
##########
tests/cli/test_cli_parser.py:
##########
@@ -229,6 +229,7 @@ def test_positive_int(self):
with pytest.raises(argparse.ArgumentTypeError):
cli_config.positive_int(allow_zero=False)("0")
+ with pytest.raises(argparse.ArgumentTypeError):
Review Comment:
I see the importance of this rule
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "potiuk (via GitHub)" <gi...@apache.org>.
potiuk commented on PR #38219:
URL: https://github.com/apache/airflow/pull/38219#issuecomment-2002506055
Yes. Even if some of the cases are not as easy to fix, it might indeed prevent some non-trivial mistakes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on code in PR #38219:
URL: https://github.com/apache/airflow/pull/38219#discussion_r1527263387
##########
tests/www/test_app.py:
##########
@@ -290,11 +288,12 @@ class TestFlaskCli:
def test_flask_cli_should_display_routes(self, capsys):
with mock.patch.dict("os.environ", FLASK_APP="airflow.www.app:cached_app"), mock.patch.object(
sys, "argv", ["flask", "routes"]
- ), pytest.raises(SystemExit):
+ ):
from flask import __main__
# We are not using run_module because of https://github.com/pytest-dev/pytest/issues/9007
- runpy.run_path(__main__.__file__, run_name="main")
+ with pytest.raises(SystemExit):
+ runpy.run_path(__main__.__file__, run_name="main")
Review Comment:
I suspect that this test will fail and didn't reach `runpy.run_path` need to check what we actually check here and why
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis commented on PR #38219:
URL: https://github.com/apache/airflow/pull/38219#issuecomment-2002384363
Interesting finding about side effects in tests, which reproduced into the current main
If run tests over `tests/www/test_app.py` module more than once some of them will fail, if execute entire `tests/www/`then all tests are pass.
```console
root@bcd8fa28cc44:/opt/airflow# pytest tests/www/test_app.py
...
============================================================================ 18 passed, 3 warnings in 10.21s ============================================================================
root@bcd8fa28cc44:/opt/airflow# pytest tests/www/test_app.py
...
FAILED tests/www/test_app.py::TestApp::test_should_respect_proxy_fix - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_base_url_ignore_proxy_headers - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_base_url_when_proxy_fix_and_base_url_is_set_up_but_headers_missing - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_base_url_and_proxy_when_proxy_fix_and_base_url_is_set_up - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_set_permanent_session_timeout - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_correct_default_is_set_for_cookie_samesite - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[sha512] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[sha384] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[sha256] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[sha224] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[sha1] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[md5] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
FAILED tests/www/test_app.py::TestApp::test_should_respect_caching_hash_method[default] - Exception: Auth Manager has not been initialized yet. The `init_auth_manager` method needs to be called first.
============================================================================= 13 failed, 4 passed in 7.10s ==============================================================================
root@bcd8fa28cc44:/opt/airflow# pytest tests/www/
tests/www/test_app.py::TestApp::test_should_respect_proxy_fix PASSED [ 0%]
tests/www/test_app.py::TestApp::test_should_respect_base_url_ignore_proxy_headers PASSED [ 0%]
tests/www/test_app.py::TestApp::test_base_url_contains_trailing_slash PASSED [ 0%]
tests/www/test_app.py::TestApp::test_should_respect_base_url_when_proxy_fix_and_base_url_is_set_up_but_headers_missing PASSED [ 0%]
tests/www/test_app.py::TestApp::test_should_respect_base_url_and_proxy_when_proxy_fix_and_base_url_is_set_up PASSED [ 0%]
...
==================================================================== 622 passed, 1167 warnings in 224.98s (0:03:44) =====================================================================
```
In both cases `tests/www/test_app.py` executed first so my suspicious about tests collections
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Partially enable PT012 rule [airflow]
Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis merged PR #38219:
URL: https://github.com/apache/airflow/pull/38219
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org