This is an automated email from the ASF dual-hosted git repository.
vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 9b4b17d44c2 Fix mock assertions in provider tests that never ran
(#77510)
9b4b17d44c2 is described below
commit 9b4b17d44c27456834b290672271bf5ad7af2807
Author: Piyush Rokade <[email protected]>
AuthorDate: Thu Nov 26 01:00:59 2026 +0530
Fix mock assertions in provider tests that never ran (#77510)
Several tests wrote `assert mock.assert_called_once` / `assert
mock.assert_not_called` without calling the method. A bound method is
always truthy, so these lines passed no matter how the mock was used.
Call the assertion methods directly instead (wrapping the call in
`assert` would always fail, since the `assert_*` helpers return None).
Affected tests: amazon (connection wrapper, base hook), openlineage
(listener), slack (webhook hook). All of them still pass, and each now
fails if its expectation is flipped.
---
.../tests/unit/amazon/aws/hooks/test_base_aws.py | 26 ++++++++++++----------
.../amazon/aws/utils/test_connection_wrapper.py | 6 ++---
.../unit/keycloak/auth_manager/test_middleware.py | 4 +---
.../unit/openlineage/plugins/test_listener.py | 6 ++---
.../tests/unit/slack/hooks/test_slack_webhook.py | 4 ++--
5 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py
b/providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py
index 38b2fada138..374b43adb93 100644
--- a/providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py
+++ b/providers/amazon/tests/unit/amazon/aws/hooks/test_base_aws.py
@@ -848,17 +848,19 @@ class TestAwsBaseHook:
mock_get.assert_called_once_with(idp_url, auth=mock_auth)
mock_xpath.assert_called_once_with(xpath)
- mocked_basic_session.assert_has_calls = [
- mock.call().client("sts", config=mock.ANY,
endpoint_url=sts_endpoint),
- mock.call()
- .client()
- .assume_role_with_saml(
- DurationSeconds=duration_seconds,
- PrincipalArn=principal_arn,
- RoleArn=role_arn,
- SAMLAssertion=encoded_saml_assertion,
- ),
- ]
+ mocked_basic_session.assert_has_calls(
+ [
+ mock.call().client("sts", config=mock.ANY,
endpoint_url=sts_endpoint),
+ mock.call()
+ .client()
+ .assume_role_with_saml(
+ DurationSeconds=duration_seconds,
+ PrincipalArn=principal_arn,
+ RoleArn=role_arn,
+ SAMLAssertion=encoded_saml_assertion,
+ ),
+ ]
+ )
@mock_aws
def test_expand_role(self):
@@ -1118,7 +1120,7 @@ class TestAwsBaseHook:
region_name=method_region_name,
config=mock.ANY,
)
- assert mock_session_factory_instance.create_session.assert_called_once
+
mock_session_factory_instance.create_session.assert_called_once_with(deferrable=False)
assert session == MOCK_BOTO3_SESSION
@pytest.mark.parametrize("verify", [None, "path/to/cert/hook-bundle.pem",
False])
diff --git
a/providers/amazon/tests/unit/amazon/aws/utils/test_connection_wrapper.py
b/providers/amazon/tests/unit/amazon/aws/utils/test_connection_wrapper.py
index e6345ade152..0c63510c4e7 100644
--- a/providers/amazon/tests/unit/amazon/aws/utils/test_connection_wrapper.py
+++ b/providers/amazon/tests/unit/amazon/aws/utils/test_connection_wrapper.py
@@ -237,12 +237,12 @@ class TestAwsConnectionWrapper:
if botocore_config:
assert wrap_conn.botocore_config == botocore_config, "Expected
provided botocore_config"
- assert mock_botocore_config.assert_not_called
+ mock_botocore_config.assert_not_called()
elif not botocore_config_kwargs:
assert wrap_conn.botocore_config is None, "Expected default
botocore_config"
- assert mock_botocore_config.assert_not_called
+ mock_botocore_config.assert_not_called()
else:
- assert mock_botocore_config.assert_called_once
+ mock_botocore_config.assert_called_once()
if botocore_config_kwargs.get("signature_version") == "unsigned":
botocore_config_kwargs["signature_version"] = UNSIGNED
assert mock.call(**botocore_config_kwargs) in
mock_botocore_config.mock_calls
diff --git
a/providers/keycloak/tests/unit/keycloak/auth_manager/test_middleware.py
b/providers/keycloak/tests/unit/keycloak/auth_manager/test_middleware.py
index 22a6c5a8cfd..7bad391eca3 100644
--- a/providers/keycloak/tests/unit/keycloak/auth_manager/test_middleware.py
+++ b/providers/keycloak/tests/unit/keycloak/auth_manager/test_middleware.py
@@ -704,9 +704,7 @@ class TestKeycloakJWTMiddleware:
None,
)
assert seen["authenticated_via"] is trusted_marker
- mock_auth_manager.refresh_user.asssert_any_call(
- user=KeycloakAuthManager._attach_keycloak_tokens(mock_user,
access_token, "refresh_token")
- )
+ mock_auth_manager.refresh_user.assert_any_call(user=mock_user)
mock_auth_manager.generate_jwt.assert_any_call(refreshed_user)
assert _get_browser_cookies(response) == {
(COOKIE_NAME_JWT_TOKEN, "/"): "new_token",
diff --git
a/providers/openlineage/tests/unit/openlineage/plugins/test_listener.py
b/providers/openlineage/tests/unit/openlineage/plugins/test_listener.py
index 35b7e28987e..da19f6ebc9c 100644
--- a/providers/openlineage/tests/unit/openlineage/plugins/test_listener.py
+++ b/providers/openlineage/tests/unit/openlineage/plugins/test_listener.py
@@ -2289,7 +2289,7 @@ class TestOpenLineageListenerAirflow3:
expected_args["run_id"] = "9d3b14f7-de91-40b6-aeef-e887e2c7673e"
adapter = OpenLineageAdapter()
adapter.fail_task(**expected_args)
- assert mock_emit.assert_called_once
+ mock_emit.assert_called_once()
@pytest.mark.parametrize(
("team_name", "expected_tags"),
@@ -2543,7 +2543,7 @@ class TestOpenLineageListenerAirflow3:
expected_args["run_id"] = "9d3b14f7-de91-40b6-aeef-e887e2c7673e"
adapter = OpenLineageAdapter()
adapter.complete_task(**expected_args)
- assert mock_emit.assert_called_once
+ mock_emit.assert_called_once()
@mock.patch(
"airflow.providers.openlineage.plugins.listener.OpenLineageListener._execute",
new=regular_call
@@ -3023,7 +3023,7 @@ class TestOpenLineageListenerAirflow3:
expected_args["run_id"] = "9d3b14f7-de91-40b6-aeef-e887e2c7673e"
adapter = OpenLineageAdapter()
adapter.complete_task(**expected_args)
- assert mock_emit.assert_called_once
+ mock_emit.assert_called_once()
@pytest.mark.parametrize(
("max_workers", "expected"),
diff --git a/providers/slack/tests/unit/slack/hooks/test_slack_webhook.py
b/providers/slack/tests/unit/slack/hooks/test_slack_webhook.py
index 56e3c7433bc..b43abb6bc32 100644
--- a/providers/slack/tests/unit/slack/hooks/test_slack_webhook.py
+++ b/providers/slack/tests/unit/slack/hooks/test_slack_webhook.py
@@ -421,7 +421,7 @@ class TestSlackWebhookHook:
hook = SlackWebhookHook(slack_webhook_conn_id=TEST_CONN_ID)
with pytest.raises(TypeError, match=r"Body expected dictionary, got
.*\."):
hook.send_dict(body=send_body)
- assert mock_webhook_client_send_dict.assert_not_called
+ mock_webhook_client_send_dict.assert_not_called()
@pytest.mark.parametrize("json_string", ["{'text': 'Single quotes'}",
'{"text": "Missing }"'])
@mock.patch("airflow.providers.slack.hooks.slack_webhook.WebhookClient")
@@ -435,7 +435,7 @@ class TestSlackWebhookHook:
error_message = r"Body expected valid JSON string, got .*\. Original
error:.*"
with pytest.raises(AirflowException, match=error_message):
hook.send_dict(body=json_string)
- assert mock_webhook_client_send_dict.assert_not_called
+ mock_webhook_client_send_dict.assert_not_called()
@pytest.mark.parametrize(
"legacy_attr",