Skip to content

Conversation

Flamefire
Copy link
Contributor

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 in build_and_install_one before processing/calling run_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.

When no changes are to be made we can exit early which especially avoids
the `module list` command whose output is unused in this case causing
unecessary overhead.
Many tests modify the environment in some steps and need to restore it
afterwards.
To avoid missing this the contextmanager does that automatically.
@Flamefire Flamefire force-pushed the restore-test-env branch 2 times, most recently from 636cc1b to 5476d7f Compare October 6, 2025 14:15
@boegel boegel changed the title Introduce context manager for restoring environment in tests Introduce saved_env context manager for restoring environment in tests Oct 8, 2025
@boegel boegel added this to the next release (5.2.0?) milestone Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants