[Devel] [PATCH vz10 32/32] kunit: add the script dir to sys.path for PYTHONSAFEPATH compatibility
Konstantin Khorenko
khorenko at virtuozzo.com
Fri Aug 21 19:37:18 MSK 2026
The RHEL10 import changed the Python shebang of the in-tree tools from
'#!/usr/bin/python3 -s' to '#!/usr/bin/python3 -sP'. The -P flag turns on
safe path mode (PYTHONSAFEPATH, Python 3.11+), which stops Python from
prepending the script's own directory to sys.path - so kunit.py cannot
import the modules sitting right next to it, and the KUnit tool does not
start at all:
$ ./tools/testing/kunit/kunit.py run
Traceback (most recent call last):
File "tools/testing/kunit/kunit.py", line 23, in <module>
import kunit_json
ModuleNotFoundError: No module named 'kunit_json'
Add the script's directory to sys.path before the local imports in the two
executable scripts that have them, kunit.py and kunit_tool_test.py,
following commit e6c430f5a2cc ("selftests/damon: add script dir to
sys.path for PYTHONSAFEPATH compatibility") which fixed the same breakage
for the DAMON selftests.
Fixes: 9f055df11343 ("rh10: import RHEL10 kernel-6.12.0-211.16.1.el10")
Feature: fix KUnit tests
https://virtuozzo.atlassian.net/browse/VSTOR-134732
Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
tools/testing/kunit/kunit.py | 1 +
tools/testing/kunit/kunit_tool_test.py | 2 ++
2 files changed, 3 insertions(+)
diff --git a/tools/testing/kunit/kunit.py b/tools/testing/kunit/kunit.py
index 13ccb9993776..b4bc6c742718 100755
--- a/tools/testing/kunit/kunit.py
+++ b/tools/testing/kunit/kunit.py
@@ -20,6 +20,7 @@ from dataclasses import dataclass
from enum import Enum, auto
from typing import Iterable, List, Optional, Sequence, Tuple
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import kunit_json
import kunit_kernel
import kunit_parser
diff --git a/tools/testing/kunit/kunit_tool_test.py b/tools/testing/kunit/kunit_tool_test.py
index 3121e133e949..265a8999aada 100755
--- a/tools/testing/kunit/kunit_tool_test.py
+++ b/tools/testing/kunit/kunit_tool_test.py
@@ -16,8 +16,10 @@ import json
import os
import signal
import subprocess
+import sys
from typing import Iterable
+sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import kunit_config
import kunit_parser
import kunit_kernel
--
2.47.1
More information about the Devel
mailing list