Skip to content

Commit

Permalink
Fix error when running unit test test_created_pod with Py3.11 (astr…
Browse files Browse the repository at this point in the history
…onomer#825)

When the CI ran:
`hatch run tests.py3.11-2.7:test-cov`

It was consistently raising the exception:
```
FAILED tests/operators/test_kubernetes.py::test_created_pod - kubernetes.config.config_exception.ConfigException: Invalid kube-config file. No configuration found.
```

Example:

https://github.com/astronomer/astronomer-cosmos/actions/runs/7726274202/job/21063656952

I could not reproduce this issue locally, even when using Python 3.11.8.
An explanation I see is that the built-in `unittest.mock` library
changed in the Python version the CI was using - and for some reason,
the way the mock was set stopped working. I changed how the mock was
defined, and things seem to work fine.
  • Loading branch information
tatiana authored and arojasb3 committed Jul 14, 2024
1 parent 5ded344 commit a5660a6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions tests/operators/test_kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ def cleanup(pod: str, remote_pod: str):
test_operator._handle_warnings(context)


@patch("airflow.providers.cncf.kubernetes.operators.pod.KubernetesPodOperator.hook")
def test_created_pod(test_hook):
test_hook.is_in_cluster = False
test_hook._get_namespace.return_value.to_dict.return_value = "foo"
def test_created_pod():
ls_kwargs = {"env_vars": {"FOO": "BAR"}}
ls_kwargs.update(base_kwargs)
ls_operator = DbtLSKubernetesOperator(**ls_kwargs)
ls_operator.hook = MagicMock()
ls_operator.hook.is_in_cluster = False
ls_operator.hook._get_namespace.return_value.to_dict.return_value = "foo"
ls_operator.build_kube_args(context={}, cmd_flags=MagicMock())
pod_obj = ls_operator.build_pod_request_obj()
expected_result = {
Expand Down

0 comments on commit a5660a6

Please sign in to comment.