Skip to content

Conversation

@topherinternational
Copy link
Contributor

@topherinternational topherinternational commented Sep 5, 2024

Looks like #41658 introduced a typo in mock assertion code, not_called() instead of assert_not_called().

This passed in Python 3.8-3.11, but Mock in 3.12 threw an error which killed 3.12 tests e.g. in #41555:

FAILED tests/providers/apache/livy/hooks/test_livy.py::TestLivyDbHook::test_post_batch_calls_get_conn_if_no_batch_id - AttributeError: 'not_called' is not a valid assertion. Use a spec for the mock if 'not_called' is meant to be an attribute.

(I guess unittest.mock in 3.12 auto-detects when you intended to assert.)


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
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.

@potiuk potiuk merged commit daa66c3 into apache:main Sep 5, 2024
@potiuk
Copy link
Member

potiuk commented Sep 5, 2024

Thanks - yeah - this is common problem for Python 3.12. Possibly we should add some static check for that.

@potiuk
Copy link
Member

potiuk commented Sep 5, 2024

The problem is that I have not seen any ready-to-use ruff or other rule for that, only Python 3.12 will start to raise those exceptions:

FAILED tests/providers/apache/livy/hooks/test_livy.py::TestLivyDbHook::test_post_batch_calls_get_conn_if_no_batch_id - AttributeError: 
'not_called' is not a valid assertion. Use a spec for the mock if 'not_called' is meant to be an attribute.

Not sure if we can automate it for Python 3.8 (and soon Python 3.9) automatically ?

@potiuk
Copy link
Member

potiuk commented Sep 5, 2024

I created an issue in ruff repo: astral-sh/ruff#13252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants