This is an automated email from the ASF dual-hosted git repository.

taragolis 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 b840c14b10 Avoid side-effects in `conf_vars` testing helper (#37438)
b840c14b10 is described below

commit b840c14b10c95644ebed6b465d43fa0f08585b74
Author: Andrey Anshin <[email protected]>
AuthorDate: Thu Feb 15 22:20:03 2024 +0400

    Avoid side-effects in `conf_vars` testing helper (#37438)
---
 tests/test_utils/config.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tests/test_utils/config.py b/tests/test_utils/config.py
index 5c1d2a3e81..e106d577f0 100644
--- a/tests/test_utils/config.py
+++ b/tests/test_utils/config.py
@@ -42,16 +42,20 @@ def conf_vars(overrides):
                 conf.add_section(section)
             conf.set(section, key, value)
         else:
-            conf.remove_option(section, key)
+            if conf.has_section(section):
+                conf.remove_option(section, key)
     settings.configure_vars()
     try:
         yield
     finally:
         for (section, key), value in original.items():
             if value is not None:
+                if not conf.has_section(section):
+                    conf.add_section(section)
                 conf.set(section, key, value)
             else:
-                conf.remove_option(section, key)
+                if conf.has_section(section):
+                    conf.remove_option(section, key)
         for env, value in original_env_vars.items():
             os.environ[env] = value
         settings.configure_vars()

Reply via email to