Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions edq/testing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(self,
base_dir: str,
data_dir: str,
temp_dir: str,
work_dir: typing.Union[str, None] = None,
cli: typing.Union[str, None] = None,
arguments: typing.Union[typing.List[str], None] = None,
error: bool = False,
Expand Down Expand Up @@ -103,6 +104,13 @@ def __init__(self,

edq.util.dirent.mkdir(temp_dir)

self.work_dir: str = os.getcwd()
""" The directory the test runs from. """

if (work_dir is not None):
work_dir_expanded = self._expand_paths(work_dir)
self.work_dir = work_dir_expanded

if (cli is None):
raise ValueError("Missing CLI module.")

Expand Down Expand Up @@ -270,6 +278,9 @@ def __method(self: edq.testing.unittest.BaseTest) -> None:
old_args = sys.argv
sys.argv = [test_info.module.__file__] + test_info.arguments

previous_work_directory = os.getcwd()
os.chdir(test_info.work_dir)

try:
with contextlib.redirect_stdout(io.StringIO()) as stdout_output:
with contextlib.redirect_stderr(io.StringIO()) as stderr_output:
Expand All @@ -290,6 +301,8 @@ def __method(self: edq.testing.unittest.BaseTest) -> None:
if (isinstance(ex, SystemExit) and (ex.__context__ is not None)):
stderr_text = self.format_error_string(ex.__context__)
finally:
os.chdir(previous_work_directory)

sys.argv = old_args

if (not test_info.split_stdout_stderr):
Expand Down