]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix pytest module detection for run.sh
authorTom Krizek <tkrizek@isc.org>
Thu, 31 Aug 2023 11:18:17 +0000 (13:18 +0200)
committerTom Krizek <tkrizek@isc.org>
Wed, 20 Sep 2023 08:32:10 +0000 (10:32 +0200)
To allow concurrent invocations of pytest, it is necessary to assign
ports properly to avoid conflicts. In order to do that, pytest needs to
know a complete list of all test modules.

When pytest is invoked from run.sh, the current working directory is the
system test directory. To properly detect other tests, the conftest.py
has to look in the bin/tests/system directory, rather than the current
working directory.

(cherry picked from commit d4502206a146b00ce1f8c1fad50a024d654b25f5)

bin/tests/system/conftest.py

index 50510a000c90ffee71652454eca3101c511b8b07..8f40ff0657aaad0d0b7ab06da4b140ed65cec0a2 100644 (file)
@@ -268,13 +268,21 @@ else:
 
     @pytest.fixture(scope="session")
     def modules():
-        """Sorted list of all modules. Used to determine port distribution."""
+        """
+        Sorted list of ALL modules.
+
+        The list includes even test modules that are not tested in the current
+        session. It is used to determine port distribution. Using a complete
+        list of all possible test modules allows independent concurrent pytest
+        invocations.
+        """
         mods = []
-        for dirpath, _dirs, files in os.walk(os.getcwd()):
+        for dirpath, _dirs, files in os.walk(FILE_DIR):
             for file in files:
                 if file.startswith("tests_") and file.endswith(".py"):
                     mod = f"{dirpath}/{file}"
-                    mods.append(mod)
+                    if not pytest_ignore_collect(mod):
+                        mods.append(mod)
         return sorted(mods)
 
     @pytest.fixture(scope="session")
@@ -282,11 +290,11 @@ else:
         """
         Dictionary containing assigned base port for every module.
 
-        Note that this is a session-wide fixture. The port numbers are
-        deterministically assigned before any testing starts. This fixture MUST
-        return the same value when called again during the same test session.
-        When running tests in parallel, this is exactly what happens - every
-        worker thread will call this fixture to determine test ports.
+        The port numbers are deterministically assigned before any testing
+        starts. This fixture MUST return the same value when called again
+        during the same test session. When running tests in parallel, this is
+        exactly what happens - every worker thread will call this fixture to
+        determine test ports.
         """
         port_min = PORT_MIN
         port_max = PORT_MAX - len(modules) * PORTS_PER_TEST