Skip to content

Fix mock assertion in Livy test#42027

Merged
potiuk merged 1 commit into
apache:mainfrom
topherinternational:fix-livy-test
Sep 5, 2024
Merged

Fix mock assertion in Livy test#42027
potiuk merged 1 commit into
apache:mainfrom
topherinternational:fix-livy-test

Conversation

@topherinternational

@topherinternational topherinternational commented Sep 5, 2024

Copy link
Copy Markdown
Contributor

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

potiuk commented Sep 5, 2024

Copy link
Copy Markdown
Member

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

@potiuk

potiuk commented Sep 5, 2024

Copy link
Copy Markdown
Member

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

potiuk commented Sep 5, 2024

Copy link
Copy Markdown
Member

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