commit: 305780c475ddff6e53e2619429ae8e3393173fdd
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Thu Nov 27 17:34:02 2025 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Nov 27 17:37:24 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=305780c4
conftest.py: only reload portage.data if needed
This prevents importlib.reload from failing when running a specific
test that does not trigger portage.data import earlier.
Fixes: 906a961e96797961a85e92f3a837142ce1a502f0
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/tests/conftest.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/lib/portage/tests/conftest.py b/lib/portage/tests/conftest.py
index 423dc264ea..2b05ed9ade 100644
--- a/lib/portage/tests/conftest.py
+++ b/lib/portage/tests/conftest.py
@@ -35,7 +35,8 @@ def prepare_environment():
# user/group configuration.
os.environ["PORTAGE_USERNAME"] = pwd.getpwuid(os.getuid()).pw_name
os.environ["PORTAGE_GRPNAME"] = grp.getgrgid(os.getgid()).gr_name
- importlib.reload(portage.data)
+ if "portage.data" in sys.modules:
+ importlib.reload(portage.data)
# Insert our parent dir so we can do shiny import "tests"
# This line courtesy of Marienz and Pkgcore ;)