Skip to content

Commit

Permalink
Moved chdir in _run_model, and made sure before raising error chdir back
Browse files Browse the repository at this point in the history
Otherwise could happen that raise came before chdir back to initial_cwd,
and unittest discovery which runs everything in one process had breaking
tests following the missed chdir back to initial_cwd
  • Loading branch information
pstelzig committed Jun 30, 2024
1 parent eaa7aa2 commit 8dc824a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions mopyregtest/modelicaregressiontest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,9 @@ def _import_and_simulate(self):
pathlib.Path.mkdir(self.result_folder_path)
self.result_folder_created = True

os.chdir(self.result_folder_path)

# Run the scripts for import and simulation
self._run_model()

os.chdir(self.initial_cwd)

return

@staticmethod
Expand Down Expand Up @@ -457,6 +453,8 @@ def _run_model(self):
out : None
"""
os.chdir(self.result_folder_path)

for tool in self.tools:
tool_executable = tool

Expand Down Expand Up @@ -528,14 +526,21 @@ def _run_model(self):

# Check output: Both simulation binary and simulation result must exist now
if not sim_binary_path.exists():
os.chdir(self.initial_cwd)

raise AssertionError(
f"The expected simulation binary at {sim_result_path} does not exist. "
+ f"Please check the output from the simulation tool:\n\n{omc_messages}")

if not sim_result_path.exists():
os.chdir(self.initial_cwd)

raise AssertionError(
f"The expected simulation result at {sim_result_path} does not exist. "
+ f"Please check the output from the simulation tool:\n\n{omc_messages}")

os.chdir(self.initial_cwd)

return

@staticmethod
Expand Down

0 comments on commit 8dc824a

Please sign in to comment.