Taragolis commented on PR #38387:
URL: https://github.com/apache/airflow/pull/38387#issuecomment-2014622776
> Add tests (any suggestions?)
Simple tests which check respect docker host, case if env set to empty
string (edge case) and if DOCKER_HOST not set
Tests usual stored into the test/{path-from-airflow-package},
e.g.[tests/providers/docker/operators/test_docker.py](https://github.com/apache/airflow/blob/main/tests/providers/docker/operators/test_docker.py)
Test environ variables might be done by
[`monkeypatch`](https://docs.pytest.org/en/latest/how-to/monkeypatch.html)
pytest fixture, something like that (just an example for the reference,
```python
class TestDockerOperator:
...
def test_respect_docker_host_env(self, monkeypatch):
monkeypatch.setenv("DOCKER_HOST", "foo.bar")
assert DockerOperator(task_id="test-task", image="test").docker_url
== "foo.bar"
def test_docker_host_env_empty(self, monkeypatch):
monkeypatch.setenv("DOCKER_HOST", "")
assert DockerOperator(task_id="test-task", image="test").docker_url
== "expected-host-here"
def test_docker_host_env_not_set(self, monkeypatch):
monkeypatch.delenv("DOCKER_HOST", raising=False)
assert DockerOperator(task_id="test-task", image="test").docker_url
== "expected-host-here"
```
> In case of backwards incompatible changes please leave a note in a
newsfragment file, named
Is it backward incompatible change?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]