-
Notifications
You must be signed in to change notification settings - Fork 191
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
reorganize plugin testing code #3319
Conversation
plugin testing code is split up from a single file fixtures.py (that actually did not contain a single fixture) over multiple files * one for the manager, which is now called TestManager (it has nothing to do with fixtures) * one for test classes & runners for use with unittest * one for (newly added) fixtures for use with pytest
957b12d
to
c1b3f5a
Compare
Sorry for the follow-up commits. Tests pass on my fork now, and I'm not planning any further commits. Let me know what you think! |
thanks, @ltalirz, I am going to adapt the cp2k plugin to use the fixtures introduced here. Once they work fine I am going to approve your PR. |
We should add a possibility to not remove the folder where the calculation was run, useful for the tests. |
both unittest test classes and pytest fixtures will now use the backend defined in the `TEST_AIIDA_BACKEND` environment variable.
for consistency (used nowhere else in the code). + see https://stackoverflow.com/a/6930223
by specifying the environment variable TEST_AIIDA_PROFILE=profilename one can use an existing profile instead of setting up a test profile automatically.
after pulling the last changes I get the following error while running pytest for the aiida-cp2k plugin:
|
Yes, adding the possibility to avoid the profile creation required a lot of
reorganization and I still need to fix a few things. Will let you know.
…On Tue, Sep 17, 2019 at 6:43 AM Aliaksandr Yakutovich < ***@***.***> wrote:
after taking the last changes I get the following error while running
pytest for the aiida-cp2k plugin:
self = <aiida.manage.configuration.profile.Profile object at 0x11ea78a10>
@Property
def default_user(self):
> return self._attributes[self.KEY_DEFAULT_USER]
E KeyError: 'default_user_email'
../aiida_core/aiida/manage/configuration/profile.py:124: KeyError
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3319?email_source=notifications&email_token=AAIBEPODNTHBS5ZFQZABPUTQKBN6HA5CNFSM4IWGMDR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD63IQTQ#issuecomment-532056142>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIBEPM5TW6WDDZPAIMNGWDQKBN6HANCNFSM4IWGMDRQ>
.
|
To give an idea of how testing is done in
The automatic comparison files generation and checking is done through the |
Just to have everything in one place - below the pointers from @greschd concerning aiida-pytest:
One thing that I’ve found to be helpful is having an option to wait for user input before wiping the test DB. That allows for inspecting the state better before it’s gone. See here: https://github.com/greschd/aiida_pytest/blob/migrate_v1/aiida_pytest/_configure.py#L152 |
@ltalirz was this something that needed to go in before the release? |
I'll continue to work on this today; also to add at least the possibility to use the pytest fixtures together with an existing AiiDA profile. However, this is not absolutely necessary for the 1.0 release. |
closing this while doing some more work. |
@sphuber Do you remember whether configuring logging is needed here: I.e. do you think this is something the fixture manager should do automatically? |
@sphuber Finally, as far as I can tell, the fixtures don't make direct use of P.S. You have rights to push to my fork, so feel free to proceed however is easiest for you. |
* fix name according to suggestion * fix bug in database query since the code label no longer referred to the full label (including hte computer), `Code.objects.get(label='network@computer')` would always turn up empty-handed, causing the utility to create a new code. Now, we're searching all available codes with the `network` label and simply take the first one (if it exists).
I actually happen to have added that just today. It was necessary to get the |
ResourceWarning introduced in python 3.2
@sphuber This would basically be ready for review. I haven't yet incorporated Dominik's additions - perhaps I'll find time but if not I think this could also be done in a separate PR. |
With `autouse=True`, there is no straightforward way for plugin authors to disable use of a fixture. While this makes sense for the `aiida_profile` fixture, we've encountered cases where resetting the database in between tests may lead to issues. This problem is solved by keeping the fixture available but requiring users to depend on it explicitly.
4879d3c
to
3b5e9ea
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 @ltalirz , some questions and comments
aiida/orm/entities.py
Outdated
Resets collection instance back to its initial state (to be constructed from scratch when next requested). | ||
Useful to clear any internal caches of the collection. | ||
""" | ||
cls._COLLECTIONS = datastructures.LazyStore() |
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 think this does what you intend it to do. This will reset the collection for all entities and backend. So when you call User.object.reset
it will reset all collections not just that of User
. I would really go for the alternative you proposed for now and implement a specific default user reset on the User
collection
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 the moment I've implemented the modification described in #3462
I can still change it if this is thought to be the worse solution.
Just a comment from my side: I used those modifications to test Beware that on travis the tests still fail because they are based on 1.0.0b6 release of |
Co-Authored-By: Sebastiaan Huber <[email protected]>
@sphuber Thanks a lot for the thorough review and the great suggestions. |
* rename TEST_AIIDA_PROFILE => AIIDA_TEST_PROFILE * rename TEST_AIIDA_BACKEND => AIIDA_TEST_BACKEND * add warning when setting AIIDA_TEST_PROFILE while running `verdi devel tests` * make test profile configurable at the test_manager level, so that the context manager can be used without having to mess with environment variables.
@sphuber I've made the changes we discussed. |
…into add-pytest-fixtures2
implement specific cache reset method for User.objects
fb1bebc
to
4ae8ade
Compare
4ae8ade
to
70c234a
Compare
Thanks a lot @ltalirz |
@ltalirz I'm just migrating |
@greschd probably not - if you have any small suggestions for improvements, now would be a good time to make a PR. By the way, sorry for not yet having included more from aiida-pytest's features, it was just lack of time on my side. I'll open an issue so that these things don't get lost and we can keep improving the fixtures. |
I haven't had the time to look at it in detail, but from the surface it looks pretty good - better than that hot mess that is |
fix #2648
fix #2660
fix #3462
The "helper" code for plugin testing is reorganized from a single file
fixtures.py
(that actually did not contain a single fixture) over multiple files.manage/tests/__init__.py
for the manager, which is now calledTestManager
(it has nothing to do with fixtures)
unittest_classes.py
for test classes & runners for use with unittestpytest_fixtures.py
for the fixtures for use with pytest (=the main new content in this PR)In order to avoid breaking the API, the old way of importing the main classes is still supported (with a corresponding deprecation warning).
Further additions:
TestManager
can now use either aTemporaryProfileManager
(which will set up the postgres cluster etc.) or aProfileManager
(which will use an existing test Profile). TheProfileManager
is used automatically when theTEST_AIIDA_PROFILE
environment variable is set.Up for discussion:
unittest_classes.py
andpytest_fixtures.py
are a bit long.I previously tried
unittest.py
andpytest.py
but this caused confusion with the external packages of the same name. Open to alternative suggestionsaiida_localhost_code
) is of a different type than the others, since it needs extra parameters. Depending on the needs of a particular code/plugin even the two provided may not be enough.I still think it is useful to have - if people feel this should not be in aiida-core, I can also remove it again.