-
Notifications
You must be signed in to change notification settings - Fork 227
Fix legacy pytest fixtures #6904
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
Fix legacy pytest fixtures #6904
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #6904 +/- ##
==========================================
+ Coverage 78.61% 79.08% +0.48%
==========================================
Files 564 565 +1
Lines 43116 43126 +10
==========================================
+ Hits 33890 34103 +213
+ Misses 9226 9023 -203 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@@ -177,7 +177,7 @@ def aiida_instance( | |||
current_profile = configuration.get_profile() | |||
current_path_variable = os.environ.get(settings.DEFAULT_AIIDA_PATH_VARIABLE, None) | |||
|
|||
dirpath_config = tmp_path_factory.mktemp('config') | |||
dirpath_config = tmp_path_factory.mktemp('config') / settings.DEFAULT_CONFIG_DIR_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.
settings.DEFAULT_CONFIG_DIR_NAME
is .aiida
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.
I don't fully understand, don' we have tests/manage/tests/test_pytest_fixtures.py for this purpose? Do we need another test file in src (plus workflow D:)?
Good point. That test file doesn't work as intended, because its part of the tests suite, it actually utilizes the new pytest fixtures (which have the same names for the most part), not the old ones. That's why to prevent this from happening I think it's better to to put the test file in src, although not ideal. Please have a look at #6882 where I removed the file and moved the tests, it might make more sense. Happy to do it here as well. |
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 for clarification. I see the need to run the pytest with the --noconftest
option to test it in isolation. But then wouldn't it be better to add this as a additional step in the ci-code
workflow? Especially, to collect for these files also code-coverage? Or is there an additional dependency when running the test from the tests
folder even with the --noconftest
option specified?
As explained in the comment, I specifically want to avoid running the .github/workflows/setup.sh, which sets up a test profile and whole lot of other things. I tried running the fixture tests before the
Not sure what you mean, I am collecting the code coverage in the new job.
Sorry, I guess I am conflating concerns about having a new CI job, and having a test file outside of tests/ folder. The problem of having it in test folder is that while you can run it separately via |
To clarify, I am happy if somebody wants to make this better as a follow-up, but I have already spent too much time on this (the original PR #6882 has 39 commits) so I'd suggest to merge this to unblock this for the 2.7.0 release and make an TODO issue. |
Fix config path in legacy aiida_instance pytest fixture Update .github/workflows/ci-code.yml Co-authored-by: Alexander Goscinski <[email protected]>
58cd7e5
to
4d17c35
Compare
I want to merge this as a merge commit with the two separate commits. @danielhollas could you check the 2 commit messages if I got it correct? I did not change the content of the PR |
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.
just for the notifier, everything okay, see message above.
This bug was introduced in PR aiidateam#6610, where the temporary config folder path was changed unintentionally. Previously, it was set to `/tmp/pytest-.../config/.aiida`, but the new setup used `/tmp/pytest-.../config/`. As a result, the daemon_client fixture failed to detect the profile, leading to subtle issues. This bug was masked by two factors: - The CI setup (`setup.sh`) which preconfigures AiiDA profiles. - The fixture definitions in `tests/conftest.py`, which interfered with the intended isolation of aiida_instance. A follow-up commit will address this entanglement by clearly separating fixture configuration and test logic.
Previously, legacy pytest fixtures were only tested via `tests/manage/tests/test_pytest_fixtures.py`. These tests were inadvertently affected by: - Fixtures in `tests/conftest.py`, which caused test contamination. - The CI environment, where AiiDA profiles were already created via setup.sh. To ensure true isolation: - The `--no-conftest` flag is now used to prevent loading `conftest.py`. - A new CI job in the ci-code workflow has been added to run these tests independently. - The test file has been relocated to the src directory to avoid interference from the main test suite.
4d17c35
to
229c35a
Compare
Commit messages looks great, thank you! |
The pytest fixture tests need to be isolated from the regular test suite to test if they can work independently from aiida-core test suite. Having them in the test suite risks them to hiddenly reuse configurations as it introduced the bug aiidateam#6904. Moving them to src means however that we ship the tests with releases which we also want to avoid. We therefore move them to the .github folder.
The pytest fixture tests need to be isolated from the regular test suite to verify that they can function independently of the aiida-core test suite. Including them in the main test suite risks inadvertently reusing configurations, which previously led to bug PR #6904 fixed. However, moving these tests to the `src` would result in them being included in distribution packages, which is undesirable. Therefore, we relocate them to the `.github` directory, ensuring they remain part of the repository but are excluded from the shipped package.
Closes #6881.
This fixes a tricky bug in the legacy pytest fixtures introduced in #6610.
Due to convoluted reasons explained below, this bug apparently only manifested for the
daemon_client
fixtures, which were failing to start the deamon with the error:In the first commit of this PR, I've added a new CI job that specifically tests these fixtures, and you can see that they are failing: https://github.com/aiidateam/aiida-core/actions/runs/15454591396/job/43504227763
So the problem was that since #6610, the temporary config folder was set differently than before: Instead of for example
/tmp/pytest/config/.aiida
it would be/tmp/pytest/config/
.This happened to work fine for most cases, but not for the daemon fixtures, because:
These fixtures use the
DaemonClient.start_daemon
method to start the daemon with the given test profile and configuration.aiida-core/src/aiida/engine/daemon/client.py
Line 516 in e768b70
The daemon process is started using a subprocess call to
verdi daemon start-circus
aiida-core/src/aiida/engine/daemon/client.py
Line 140 in e768b70
To ensure that the verdi command picks up the correct configuration and profile, the subprocess call sets the
AIIDA_PATH
variable to the current config folder.aiida-core/src/aiida/engine/daemon/client.py
Line 225 in e768b70
The launched verdi command parses the AIIDA_PATH in
aiida.manage.configurations.settings._get_configuration_directory_from_envvar
. This function however has a rather confusing logic where ifAIIDA_PATH
is set to a path that does not end with.aiida/
folder, the.aiida
folder gets appended automatically.💥
The smoking gun was there all along --- this innocent warning
was telling us what had happened: The verdi command thought the config folder was
/tmp/pytest-of-runner/pytest-0/config0/.aiida
, whereas we've set it to/tmp/pytest-of-runner/pytest-0/config0/
. It then went on to create and empty configuration, and then promptly failed as it did not contain the given profile.The fix and tests here are intentionally minimal to speed up review for 2.7.0 release.
There are couple of follow-ups:
src/aiida/manage/tests
module #6903._get_configuration_directory_from_envvar
should be extended so that this problem would not appear in the first place. I'll open a separate issue for that.