Taragolis commented on code in PR #33546:
URL: https://github.com/apache/airflow/pull/33546#discussion_r1299317031
##########
tests/core/test_configuration.py:
##########
@@ -549,17 +548,13 @@ def test_getsection(self):
assert test_conf.getsection("non_existent_section") is None
- def test_get_section_should_respect_cmd_env_variable(self):
- with tempfile.NamedTemporaryFile(delete=False) as cmd_file:
- cmd_file.write(b"#!/usr/bin/env bash\n")
- cmd_file.write(b"echo -n difficult_unpredictable_cat_password\n")
- cmd_file.flush()
- os.chmod(cmd_file.name, 0o0555)
- cmd_file.close()
-
- with mock.patch.dict("os.environ",
{"AIRFLOW__WEBSERVER__SECRET_KEY_CMD": cmd_file.name}):
- content = conf.getsection("webserver")
- os.unlink(cmd_file.name)
+ def test_get_section_should_respect_cmd_env_variable(self, tmp_path):
+ path = tmp_path / "testfile.sh"
+ path.write_text("#!/usr/bin/env bash\necho -n
difficult_unpredictable_cat_password\n")
+ path.chmod(0o0555)
Review Comment:
I'd rather keep original name of variable, because `path` it refers to
something abstract, in opposite of `cmd_file ` which directly refers that it is
file for command
##########
tests/core/test_configuration.py:
##########
@@ -549,17 +548,13 @@ def test_getsection(self):
assert test_conf.getsection("non_existent_section") is None
- def test_get_section_should_respect_cmd_env_variable(self):
- with tempfile.NamedTemporaryFile(delete=False) as cmd_file:
- cmd_file.write(b"#!/usr/bin/env bash\n")
- cmd_file.write(b"echo -n difficult_unpredictable_cat_password\n")
- cmd_file.flush()
- os.chmod(cmd_file.name, 0o0555)
- cmd_file.close()
-
- with mock.patch.dict("os.environ",
{"AIRFLOW__WEBSERVER__SECRET_KEY_CMD": cmd_file.name}):
- content = conf.getsection("webserver")
- os.unlink(cmd_file.name)
+ def test_get_section_should_respect_cmd_env_variable(self, tmp_path):
+ path = tmp_path / "testfile.sh"
+ path.write_text("#!/usr/bin/env bash\necho -n
difficult_unpredictable_cat_password\n")
+ path.chmod(0o0555)
+
+ with mock.patch.dict("os.environ",
{"AIRFLOW__WEBSERVER__SECRET_KEY_CMD": os.fspath(path)}):
+ content = conf.getsection("webserver")
Review Comment:
This section also could be simplified by use
[`monkeypatch`](https://docs.pytest.org/en/latest/how-to/monkeypatch.html)
fixture
```suggestion
monkeypatch.setenv("AIRFLOW__WEBSERVER__SECRET_KEY_CMD", str(path))
content = conf.getsection("webserver")
```
--
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]