Skip to content

Commit 6abe53a

Browse files
author
Theofilos Manitaras
committed
Fix crash on creation a regression test interactively
* Also create `is_interactive` function in `os_ext` to check whether the session is interactive. * Add unittest for the above function.
1 parent 38e94a2 commit 6abe53a

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

reframe/core/pipeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,10 @@ def __new__(cls, *args, **kwargs):
670670
try:
671671
prefix = cls._rfm_custom_prefix
672672
except AttributeError:
673-
prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls)))
673+
if os_ext.is_interactive():
674+
prefix = os.getcwd()
675+
else:
676+
prefix = os.path.abspath(os.path.dirname(inspect.getfile(cls)))
674677

675678
obj._rfm_init(name, prefix)
676679
return obj

reframe/utility/os_ext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,11 @@ def inpath(entry, pathvar):
227227
return entry in set(pathvar.split(':'))
228228

229229

230+
def is_interactive():
231+
'''Returns whether the given Python session is interactive'''
232+
return bool(getattr(sys, 'ps1', sys.flags.interactive))
233+
234+
230235
def subdirs(dirname, recurse=False):
231236
'''Returns a list of dirname + its subdirectories. If recurse is True,
232237
recursion is performed in pre-order.'''

unittests/test_utility.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ def test_samefile(self):
173173
os.path.join(prefix, 'broken1'))
174174
shutil.rmtree(prefix)
175175

176+
def test_is_interactive(self):
177+
# Set `sys.ps1` to immitate an interactive session
178+
sys.ps1 = 'rfm>>> '
179+
assert os_ext.is_interactive()
180+
176181
def test_is_url(self):
177182
repo_https = 'https://github.com/eth-cscs/reframe.git'
178183
repo_ssh = '[email protected]:eth-cscs/reframe.git'

0 commit comments

Comments
 (0)