commit:     3110ec376cbcb1f5b7fb82ba30ec958798bb32cf
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Tue Feb 13 00:46:52 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Tue Feb 13 05:04:40 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3110ec37

actions: Fix interaction between start-method and pytest-xdist

Use portage.test.TestCase setUp method to setup the multiprocessing
start method if needed. It needs to be done relatively late in order
to work with the pytest-xdist plugin due to execnet usage.

Bug: https://bugs.gentoo.org/914876
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 .github/workflows/ci.yml                                |  2 +-
 lib/portage/tests/__init__.py                           | 12 +++++++++++-
 lib/portage/tests/env/config/test_PortageModulesFile.py |  3 ++-
 lib/portage/tests/news/test_NewsItem.py                 |  3 ++-
 lib/portage/tests/sets/files/test_config_file_set.py    |  3 ++-
 lib/portage/tests/sets/files/test_static_file_set.py    |  3 ++-
 lib/portage/tests/sets/shell/test_shell.py              |  4 ++--
 lib/portage/tests/util/futures/test_retry.py            |  1 +
 8 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 15da507238..5bffd97206 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -82,7 +82,6 @@ jobs:
               mv "${bin_file}"{.new,}
             fi
           done < <(find bin -maxdepth 1 -type f)
-          sed -i meson.build -e "s|'-m', 'pytest'|'-c', 'import 
multiprocessing, sys, pytest; multiprocessing.set_start_method(\"spawn\", 
force=True); sys.exit(pytest.console_main())'|"
       - name: Test meson install --destdir /tmp/install-root
         run: |
           echo -e "[binaries]\npython = '$(command -v python)'" > 
/tmp/native.ini
@@ -90,5 +89,6 @@ jobs:
           meson install -C /tmp/build --destdir /tmp/install-root
       - name: Run tests for ${{ matrix.python-version }}
         run: |
+          [[ "${{ matrix.start-method }}" == "spawn" ]] && export 
PORTAGE_MULTIPROCESSING_START_METHOD=spawn
           export PYTEST_ADDOPTS="-vv -ra -l -o console_output_style=count -n 
$(nproc) --dist=worksteal"
           meson test -C /tmp/build --verbose

diff --git a/lib/portage/tests/__init__.py b/lib/portage/tests/__init__.py
index ef59852989..23dd366d89 100644
--- a/lib/portage/tests/__init__.py
+++ b/lib/portage/tests/__init__.py
@@ -1,8 +1,9 @@
 # tests/__init__.py -- Portage Unit Test functionality
-# Copyright 2006-2023 Gentoo Authors
+# Copyright 2006-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import argparse
+import multiprocessing
 import sys
 import time
 import unittest
@@ -79,6 +80,15 @@ class TestCase(unittest.TestCase):
         self.bindir = cnf_bindir
         self.sbindir = cnf_sbindir
 
+    def setUp(self):
+        """
+        Setup multiprocessing start method if needed. It needs to be
+        done relatively late in order to work with the pytest-xdist
+        plugin due to execnet usage.
+        """
+        if os.environ.get("PORTAGE_MULTIPROCESSING_START_METHOD") == "spawn":
+            multiprocessing.set_start_method("spawn", force=True)
+
     def assertRaisesMsg(self, msg, excClass, callableObj, *args, **kwargs):
         """Fail unless an exception of class excClass is thrown
         by callableObj when invoked with arguments args and keyword

diff --git a/lib/portage/tests/env/config/test_PortageModulesFile.py 
b/lib/portage/tests/env/config/test_PortageModulesFile.py
index f9879df687..bca86e0e6c 100644
--- a/lib/portage/tests/env/config/test_PortageModulesFile.py
+++ b/lib/portage/tests/env/config/test_PortageModulesFile.py
@@ -1,4 +1,4 @@
-# Copyright 2006-2009 Gentoo Foundation
+# Copyright 2006-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from portage import os
@@ -13,6 +13,7 @@ class PortageModulesFileTestCase(TestCase):
     modules = ["spanky", "zmedico", "antarus", "ricer", "5", "6"]
 
     def setUp(self):
+        super().setUp()
         self.items = {}
         for k, v in zip(self.keys + self.invalid_keys, self.modules):
             self.items[k] = v

diff --git a/lib/portage/tests/news/test_NewsItem.py 
b/lib/portage/tests/news/test_NewsItem.py
index a7903f07e4..7a8393c51f 100644
--- a/lib/portage/tests/news/test_NewsItem.py
+++ b/lib/portage/tests/news/test_NewsItem.py
@@ -1,5 +1,5 @@
 # test_NewsItem.py -- Portage Unit Testing Functionality
-# Copyright 2007-2023 Gentoo Authors
+# Copyright 2007-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from portage.tests import TestCase
@@ -114,6 +114,7 @@ class NewsItemTestCase(TestCase):
     }
 
     def setUp(self) -> None:
+        super().setUp()
         self.profile_base = "/var/db/repos/gentoo/profiles/default-linux"
         self.profile = f"{self.profile_base}/x86/2007.0/"
         self.keywords = "x86"

diff --git a/lib/portage/tests/sets/files/test_config_file_set.py 
b/lib/portage/tests/sets/files/test_config_file_set.py
index 81419df4aa..fdb28da7f6 100644
--- a/lib/portage/tests/sets/files/test_config_file_set.py
+++ b/lib/portage/tests/sets/files/test_config_file_set.py
@@ -1,5 +1,5 @@
 # testConfigFileSet.py -- Portage Unit Testing Functionality
-# Copyright 2007 Gentoo Foundation
+# Copyright 2007-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import tempfile
@@ -13,6 +13,7 @@ class ConfigFileSetTestCase(TestCase):
     """Simple Test Case for ConfigFileSet"""
 
     def setUp(self):
+        super().setUp()
         fd, self.testfile = tempfile.mkstemp(
             suffix=".testdata", prefix=self.__class__.__name__, text=True
         )

diff --git a/lib/portage/tests/sets/files/test_static_file_set.py 
b/lib/portage/tests/sets/files/test_static_file_set.py
index a4e6c29c29..e8f51ca20b 100644
--- a/lib/portage/tests/sets/files/test_static_file_set.py
+++ b/lib/portage/tests/sets/files/test_static_file_set.py
@@ -1,5 +1,5 @@
 # testStaticFileSet.py -- Portage Unit Testing Functionality
-# Copyright 2007 Gentoo Foundation
+# Copyright 2007-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import tempfile
@@ -13,6 +13,7 @@ class StaticFileSetTestCase(TestCase):
     """Simple Test Case for StaticFileSet"""
 
     def setUp(self):
+        super().setUp()
         fd, self.testfile = tempfile.mkstemp(
             suffix=".testdata", prefix=self.__class__.__name__, text=True
         )

diff --git a/lib/portage/tests/sets/shell/test_shell.py 
b/lib/portage/tests/sets/shell/test_shell.py
index f30b72a8be..15f8907dfd 100644
--- a/lib/portage/tests/sets/shell/test_shell.py
+++ b/lib/portage/tests/sets/shell/test_shell.py
@@ -1,5 +1,5 @@
 # testCommandOututSet.py -- Portage Unit Testing Functionality
-# Copyright 2007-2020 Gentoo Authors
+# Copyright 2007-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from portage.process import find_binary
@@ -11,7 +11,7 @@ class CommandOutputSetTestCase(TestCase):
     """Simple Test Case for CommandOutputSet"""
 
     def setUp(self):
-        pass
+        super().setUp()
 
     def tearDown(self):
         pass

diff --git a/lib/portage/tests/util/futures/test_retry.py 
b/lib/portage/tests/util/futures/test_retry.py
index 6bd3f4b64a..2197f6697c 100644
--- a/lib/portage/tests/util/futures/test_retry.py
+++ b/lib/portage/tests/util/futures/test_retry.py
@@ -221,6 +221,7 @@ class RetryForkExecutorTestCase(RetryTestCase):
             self._executor = None
 
     def setUp(self):
+        super().setUp()
         self._setUpExecutor()
 
     def tearDown(self):

Reply via email to