Introduce saved_env
context manager for restoring environment in tests
#5015
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Many tests modify the environment in some steps and need to restore it afterwards.
To avoid missing this the contextmanager does that automatically which avoids repeating the logic in various tests
I recently ran into this issue where a test failed with a misleading error.
Broader question: Should
EasyBlock.run_all_steps
restore the environment? When it exits it will have e.g. toolchain modules still loaded.We currently save the environment in
build_and_install_software
and restore it inbuild_and_install_one
before processing/callingrun_all_steps
, although that additionally catches changes done by hooks. However the changes done to the environment when loading the hooks are only in effect for the first installation as then the hooks are cached. So I think we can ignore that case.