Skip to content

Commit cac5517

Browse files
author
Vasileios Karakasis
authored
Merge pull request #1214 from teojgo/bugfix/interactive_crash
[bugfix] Fix crash when creating a regression test interactively
2 parents 984d7b7 + 0c0d7c5 commit cac5517

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-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 hasattr(sys, 'ps1') or 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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,17 @@ def test_samefile(self):
173173
os.path.join(prefix, 'broken1'))
174174
shutil.rmtree(prefix)
175175

176+
# FIXME: This should be changed in order to use the `monkeypatch`
177+
# fixture of `pytest` instead of creating an instance of `MonkeyPatch`
178+
def test_is_interactive(self):
179+
from _pytest.monkeypatch import MonkeyPatch # noqa: F401, F403
180+
181+
monkey = MonkeyPatch()
182+
with monkey.context() as c:
183+
# Set `sys.ps1` to immitate an interactive session
184+
c.setattr(sys, 'ps1', 'rfm>>> ', raising=False)
185+
assert os_ext.is_interactive()
186+
176187
def test_is_url(self):
177188
repo_https = 'https://github.com/eth-cscs/reframe.git'
178189
repo_ssh = '[email protected]:eth-cscs/reframe.git'

0 commit comments

Comments
 (0)