-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixtures: Fix bug in reset of empty_config
fixture
#5717
Fixtures: Fix bug in reset of empty_config
fixture
#5717
Conversation
731b2fb
to
b1910cb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks @sphuber !
great that you managed to track this down to make the tests more reproducible.
I have a few minor suggestions for further improvement
tests/conftest.py
Outdated
@@ -229,6 +229,12 @@ def empty_config(tmp_path) -> Config: | |||
configuration.CONFIG = current_config | |||
manager.load_profile(current_profile_name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
by the way, if the goal is strictly to reconstruct the state before this fixture was called, then I guess in principle one should check whether the "current profile" was loaded before or not.
I see that the current Manager
implementation does not provide information on whether that was actually the case.
It may make sense to add an
@property
def is_profile_loaded(self):
return self._profile is not None
property in the Manager
class (could also be used inside the manager implementation in some places)
bedd77b
to
7793c76
Compare
The `empty_config` fixture creates a completely independent configuration directory which allows test to manipulate the config and its contents, such as the profiles, for the duration of the test without affecting pre-existing config directories. To accomplish this, the `AIIDA_PATH` environment variable, which indicates the location of the configuration directory, is set to a temporary directory. The fixture then calls the method `aiida.manage.configuration.settings.set_configuration_directory` which will set a number of global variables that define important directory and file locations within the configuration folder, for example the location of important daemon files. The bug was that these global variables weren't reset after the end of the fixture. This means that operations performed by the daemon client, such as checking whether the daemon is running, which rely on these filepaths being set correctly, would fail. The solution therefore is to call `set_configuration_directory` once again, to revert the global variables to their previous values. This same problem also occurred in the `cache_aiida_path_variable` fixture defined and used in `tests/manage/configuration/test_config.py`. An explicit call after the `finally` in the fixture is necessary to reset the global variables. Finally, `test_environment_variable_not_set` set the value of the `DEFAULT_AIIDA_PATH` variable to a temporary directory, however, it never changed it back to the default `~`. This would essentially cause the `set_configuration_directory` be ineffective if the `AIIDA_PATH` variable was never set before running the tests, as then the value of `DEFAULT_AIIDA_PATH` would be used, which was still the temporary directory of the test. This would break any following tests that rely on the global variables in the `settings` module to be properly set.
7793c76
to
7fc2338
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot @sphuber !
looks great to me, as well as easier to follow
The
empty_config
fixture creates a completely independent configuration directory which allows test to manipulate the config and its contents, such as the profiles, for the duration of the test without affecting pre-existing config directories.To accomplish this, the
AIIDA_PATH
environment variable, which indicates the location of the configuration directory, is set to a temporary directory. The fixture then calls the methodaiida.manage.configuration.settings.set_configuration_directory
which will set a number of global variables that define important directory and file locations within the configuration folder, for example the location of important daemon files.The bug was that these global variables weren't reset after the end of the fixture. This means that operations performed by the daemon client, such as checking whether the daemon is running, which rely on these filepaths being set correctly, would fail. The solution therefore is to call
set_configuration_directory
once again, to revert the global variables to their previous values.This same problem also occurred in the
cache_aiida_path_variable
fixture defined and used intests/manage/configuration/test_config.py
. An explicit call after thefinally
in the fixture is necessary to reset the global variables.Finally,
test_environment_variable_not_set
set the value of theDEFAULT_AIIDA_PATH
variable to a temporary directory, however, it never changed it back to the default~
. This would essentially cause theset_configuration_directory
be ineffective if theAIIDA_PATH
variable was never set before running the tests, as then the value ofDEFAULT_AIIDA_PATH
would be used, which was still the temporary directory of the test. This would break any following tests that rely on the global variables in thesettings
module to be properly set.