Restore cwd after do_command error WIP#507
Conversation
|
It would be better if |
|
You can use try/except blocks inside a contextlib.contextmanager function like pushd. I think replacing the try:
yield
except Exception:
raise
finally:
os.chdir(previous_dir)would resolve the issue and be much more general We can also then test pushd directly: dir = os.getcwd()
with self.AssertRaises(RuntimeError):
with pushd('data'):
raise RuntimeError('testing')
self.assertPathsEqual(dir, os.getcwd()) |
|
Yes I think adding try:
yield
finally:
os.chdir(previous_dir)is needed Line 1317 in 5b80eb8 |
WardBrian
left a comment
There was a problem hiding this comment.
I think it would be better to make the changes to pushd directly. We can then test the behavior for that directly (though there's no harm leaving the test for do_command)
|
@maedoc Let me know if you'd prefer if myself or Ari take the PR from here in terms of changes. Thanks for finding this issue and jumping on it so quickly! |
|
All the test failures are trying to compile the model with CmdStan on macOS. The error is the same as when I try to use a CmdStan build for x86_64 on Rosetta on macOS from Python running on arm64, or vice versa. Perhaps the CI script needs to be updated to check arch and rebuild CmdStan accordingly. Also, improving CmdStanPy's support for the architecture issue on macOS would be helpful at some point. |
|
I believe the error is because GitHub Actions updated the version of MacOs used but is caching old cmdstans. I’ll look into it Thanks for the changes! I believe that with assertRaises there’s no need for a try/except in the test code. Other than that it looks great and I’ll merge once I fix the CI issues |
Some static analysers don't know that |
|
We're not using try/except anywhere else in the tests where we use assertRaises, so for consistency I think don't here |
|
The one test failure is from a timeout (I think we tried to download cmdstan too many times in short succession) so this is good to go |
|
Thanks again @maedoc ! |
Submission Checklist
Summary
Addresses #506.
Copyright and Licensing
Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): myself
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses: