]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Move env var initialization to isctest.vars
authorTom Krizek <tkrizek@isc.org>
Wed, 28 Feb 2024 16:04:40 +0000 (17:04 +0100)
committerNicki Křížek <nicki@isc.org>
Thu, 9 May 2024 15:08:10 +0000 (17:08 +0200)
Make sure all initialization takes place in isctest.vars.__init__ and
export the initial env vars there. Remove the no longer needed env
fixture and use os.environ instead.

bin/tests/system/conftest.py
bin/tests/system/isctest/vars/__init__.py
bin/tests/system/isctest/vars/openssl.py

index 8813dadd086898ab42f3c55cb57c4207a31b1e63..77b1948eaf93bd5fb6c78564002225c15569ead7 100644 (file)
@@ -17,7 +17,7 @@ import shutil
 import subprocess
 import tempfile
 import time
-from typing import Any, Dict, List, Optional
+from typing import Any, List, Optional
 
 import pytest
 
@@ -65,14 +65,6 @@ PRIORITY_TESTS_RE = re.compile("|".join(PRIORITY_TESTS))
 SYSTEM_TEST_NAME_RE = re.compile(f"{SYSTEM_TEST_DIR_GIT_PATH}" + r"/([^/]+)")
 SYMLINK_REPLACEMENT_RE = re.compile(r"/tests(_.*)\.py")
 
-# ---------------------- Module initialization ---------------------------
-
-# Set environment variables for tests.
-os.environ.update(isctest.vars.ALL)
-isctest.log.debug(
-    "variables in env: %s", ", ".join([str(key) for key in isctest.vars.ALL])
-)
-
 # ----------------------- Global requirements ----------------------------
 
 isctest.check.is_executable(isctest.vars.ALL["PYTHON"], "Python interpreter required")
@@ -256,14 +248,6 @@ def control_port():
     return int(os.environ["CONTROLPORT"])
 
 
-@pytest.fixture(scope="module")
-def env():
-    """Dictionary containing environment variables for the test."""
-    env = dict(isctest.vars.ALL)
-    os.environ.update(env)
-    return env
-
-
 @pytest.fixture(scope="module")
 def system_test_name(request):
     """Name of the system test directory."""
@@ -413,7 +397,6 @@ def system_test_dir(
 
 
 def _run_script(  # pylint: disable=too-many-arguments
-    env,
     system_test_dir: Path,
     interpreter: str,
     script: str,
@@ -437,7 +420,6 @@ def _run_script(  # pylint: disable=too-many-arguments
     cmd = [interpreter, script] + args
     with subprocess.Popen(
         cmd,
-        env=env,
         stdout=subprocess.PIPE,
         stderr=subprocess.STDOUT,
         bufsize=1,
@@ -455,15 +437,15 @@ def _run_script(  # pylint: disable=too-many-arguments
 
 
 @pytest.fixture(scope="module")
-def shell(env, system_test_dir):
+def shell(system_test_dir):
     """Function to call a shell script with arguments."""
-    return partial(_run_script, env, system_test_dir, env["SHELL"])
+    return partial(_run_script, system_test_dir, os.environ["SHELL"])
 
 
 @pytest.fixture(scope="module")
-def perl(env, system_test_dir):
+def perl(system_test_dir):
     """Function to call a perl script with arguments."""
-    return partial(_run_script, env, system_test_dir, env["PERL"])
+    return partial(_run_script, system_test_dir, os.environ["PERL"])
 
 
 @pytest.fixture(scope="module")
@@ -479,7 +461,6 @@ def run_tests_sh(system_test_dir, shell):
 @pytest.fixture(scope="module", autouse=True)
 def system_test(  # pylint: disable=too-many-arguments,too-many-statements
     request,
-    env: Dict[str, str],
     system_test_dir,
     shell,
     perl,
@@ -508,7 +489,7 @@ def system_test(  # pylint: disable=too-many-arguments,too-many-statements
 
     def check_net_interfaces():
         try:
-            perl("testsock.pl", ["-p", env["PORT"]])
+            perl("testsock.pl", ["-p", os.environ["PORT"]])
         except subprocess.CalledProcessError as exc:
             isctest.log.error("testsock.pl: exited with code %d", exc.returncode)
             pytest.skip("Network interface aliases not set up.")
@@ -532,7 +513,7 @@ def system_test(  # pylint: disable=too-many-arguments,too-many-statements
 
     def start_servers():
         try:
-            perl("start.pl", ["--port", env["PORT"], system_test_dir.name])
+            perl("start.pl", ["--port", os.environ["PORT"], system_test_dir.name])
         except subprocess.CalledProcessError as exc:
             isctest.log.error("Failed to start servers")
             pytest.fail(f"start.pl exited with {exc.returncode}")
@@ -553,7 +534,7 @@ def system_test(  # pylint: disable=too-many-arguments,too-many-statements
             pytest.fail(f"get_core_dumps.sh exited with {exc.returncode}")
 
     isctest.log.info(f"test started: {request.node.name}")
-    port = int(env["PORT"])
+    port = int(os.environ["PORT"])
     isctest.log.info(
         "using port range: <%d, %d>", port, port + isctest.vars.ports.PORTS_PER_TEST - 1
     )
index b12df88f7096e798d2646d05e3b0ac759e500694..d4e26a892f32dfe08b8d640236b4ff0e669cd257 100644 (file)
@@ -9,4 +9,15 @@
 # See the COPYRIGHT file distributed with this work for additional
 # information regarding copyright ownership.
 
+import os
+
 from .all import ALL
+from .openssl import parse_openssl_config
+from .. import log
+
+
+# env variable initialization
+parse_openssl_config(ALL["OPENSSL_CONF"])
+
+os.environ.update(ALL)
+log.debug("setting following env vars: %s", ", ".join([str(key) for key in ALL]))
index 5659222c09da199999b724381c38c06b1a7376aa..9ad20209384761a4c878c74d80c2f013adbd8340 100644 (file)
@@ -50,6 +50,3 @@ def parse_openssl_config(path: Optional[str]):
                     log.debug(
                         "SOFTHSM2_MODULE set to {OPENSSL_VARS['SOFTHSM2_MODULE']}"
                     )
-
-
-parse_openssl_config(OPENSSL_VARS["OPENSSL_CONF"])