[Devel] [PATCH RHEL10 COMMIT] kunit: add the script dir to sys.path for PYTHONSAFEPATH compatibility

Konstantin Khorenko khorenko at virtuozzo.com
Fri Aug 21 19:42:31 MSK 2026


The commit is pushed to "branch-rh10-6.12.0-211.39.1.16.x.vz10-ovz" and will appear at git at bitbucket.org:openvz/vzkernel.git
after rh10-6.12.0-211.39.1.16.6.vz10
------>
commit 7a2f379b54dc30a92d1f758221cddbb78f7c1f74
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Fri Aug 21 18:37:18 2026 +0200

    kunit: add the script dir to sys.path for PYTHONSAFEPATH compatibility
    
    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 13ccb99937764..b4bc6c7427182 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 3121e133e9492..265a8999aada7 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


More information about the Devel mailing list