Skip to content

Commit

Permalink
prepend test dir to sys.path in lib.runtest
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Jaburek <[email protected]>
  • Loading branch information
comps authored and mildas committed Mar 20, 2024
1 parent a7003c0 commit 06a8a6b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/runtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ def _alarm_timed_out(signum, frame):
# we don't need to have our logs spammed by good advice
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

# get test.py absolute path now, as we're changing CWD below
test_script = Path(sys.argv[1]).absolute()

# RHEL-8 (seemingly all python versions, even ones that are fine on RHEL-9+)
# has broken sys.path handling by runpy, which inserts empty '' into it,
# rather than the directory containing the script
# work around this by doing the insertion ourselves here - at worst, it'll be
# there twice, causing no harm
sys.path.insert(0, str(test_script.parent))

# run inside a temporary directory
# - this is because TMT is happy to run multiple tests inside the same dir,
# if all the tests are defined in .fmf files inside one directory
Expand All @@ -73,7 +83,6 @@ def _alarm_timed_out(signum, frame):
# it doesn't rely on CWD) and you can access non-module files via either
# importlib.resources or (more realistically) by using the current file:
# Path(inspect.getfile(inspect.currentframe())).parent
test_script = Path(sys.argv[1]).absolute()
with tempfile.TemporaryDirectory() as tmpdir:
os.chdir(tmpdir)
try:
Expand Down

0 comments on commit 06a8a6b

Please sign in to comment.