33#
44# SPDX-License-Identifier: BSD-3-Clause
55
6+ import contextlib
7+ import io
68import itertools
79import os
8- import pathlib
910import pytest
1011import re
1112import sys
12- from contextlib import redirect_stdout , redirect_stderr , suppress
13- from io import StringIO
1413
15- import reframe .core .config as config
1614import reframe .core .environments as env
1715import reframe .core .logging as logging
1816import reframe .core .runtime as rt
@@ -26,11 +24,11 @@ def run_command_inline(argv, funct, *args, **kwargs):
2624 sys .argv = argv
2725 exitcode = None
2826
29- captured_stdout = StringIO ()
30- captured_stderr = StringIO ()
27+ captured_stdout = io . StringIO ()
28+ captured_stderr = io . StringIO ()
3129 print (* sys .argv )
32- with redirect_stdout (captured_stdout ):
33- with redirect_stderr (captured_stderr ):
30+ with contextlib . redirect_stdout (captured_stdout ):
31+ with contextlib . redirect_stderr (captured_stderr ):
3432 try :
3533 with rt .temp_runtime (None ):
3634 exitcode = funct (* args , ** kwargs )
@@ -591,13 +589,13 @@ def test_unload_module(run_reframe, user_exec_ctx):
591589 assert returncode == 0
592590
593591
594- def test_unuse_module_path (run_reframe , user_exec_ctx , monkeypatch ):
592+ def test_unuse_module_path (run_reframe , user_exec_ctx ):
595593 ms = rt .runtime ().modules_system
596594 if ms .name == 'nomod' :
597595 pytest .skip ('no modules system found' )
598596
599597 module_path = 'unittests/modules'
600- monkeypatch . setenv ( 'MODULEPATH' , module_path )
598+ ms . searchpath_add ( module_path )
601599 returncode , stdout , stderr = run_reframe (
602600 more_options = [f'--module-path=-{ module_path } ' , '--module=testmod_foo' ],
603601 config_file = fixtures .USER_CONFIG_FILE , action = 'run' ,
@@ -632,6 +630,9 @@ def test_overwrite_module_path(run_reframe, user_exec_ctx):
632630 pytest .skip ('no modules system found' )
633631
634632 module_path = 'unittests/modules'
633+ with contextlib .suppress (KeyError ):
634+ module_path += f':{ os .environ ["MODULEPATH" ]} '
635+
635636 returncode , stdout , stderr = run_reframe (
636637 more_options = [f'--module-path={ module_path } ' , '--module=testmod_foo' ],
637638 config_file = fixtures .USER_CONFIG_FILE , action = 'run' ,
0 commit comments