Skip to content
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

WIP: Plugin fixtures #716

Merged
merged 22 commits into from Oct 20, 2017
Merged

WIP: Plugin fixtures #716

merged 22 commits into from Oct 20, 2017

Conversation

DropD
Copy link
Contributor

@DropD DropD commented Sep 22, 2017

Add fixtures that plugins can use in their tests.

The FixtureManager class can set up a complete separate, temporary aiida environment for the duration of a test.

A simple use example is:

fixtures = FixtureManager()
fixtures.create_aiida_db()
fixtures.create_profile()
# now, the dbenv is loaded, all is ready
fixtures.destroy_all()
# now the db and all files are deleted

Alternatively the contextmanager may be used:

with plugin_fixture() as fixtures:
    fixtures.create_aiida_db()
    fixtures.create_profile()
    # ready for tests
# everything cleaned up
  • An example of how to use it with unittest is included in aiida.utils.fixtures.PluginTestCase.
  • An example for pytest is to be found in github.com/DropD/aiida-vasp in aiida_vasp.calcs.tests.test_base

@DropD
Copy link
Contributor Author

DropD commented Sep 22, 2017

Also of interest to @broeder-j and all other plugin developers

@ltalirz
Copy link
Member

ltalirz commented Sep 22, 2017

Very nice! Could you perhaps also add one example of how to use it? (or point me to where it is used)

@DropD
Copy link
Contributor Author

DropD commented Sep 22, 2017

updated the description with examples

@ltalirz
Copy link
Member

ltalirz commented Sep 22, 2017

@DropD Sorry if I am overlooking it - but where did you update the description?

@DropD
Copy link
Contributor Author

DropD commented Sep 22, 2017

The description of the PR

@DropD
Copy link
Contributor Author

DropD commented Sep 22, 2017

Examples are now also in the docstrings

@DropD DropD changed the title Plugin fixtures WIP: Plugin fixtures Sep 22, 2017
@DropD
Copy link
Contributor Author

DropD commented Sep 22, 2017

Adding WIP status, because although destroy_all cleans u all the resources, it does not "unload" the dbenv. Thus, only one fixture manager can be used per test run, that means for all tests in an entire project. Therefore, there has to be at least a way to reset the database / repository to after migrations but before user / test interaction.

@ltalirz
Copy link
Member

ltalirz commented Sep 22, 2017

Thanks, indeed I overlooked that ;)
Sorry for keeping pressing on this, I'm sure for you it's trivial, but I still think it would be really helpful to have one simple, but complete unittest example in the aiida source code that makes use of the fixtures.

For example, should users simply inherit from aiida.utils.fixtures.PluginTestCase or should they re-implement what it does?
I think one actual 'demo' (can be in any other part of the code) would really make it easy to understand.

@ltalirz
Copy link
Member

ltalirz commented Oct 20, 2017

Let me know, when to go through it again!

BACKEND = <load from env variable etc>
BACKEND = os.environ.get('TEST_BACKEND')
# load the backend to be tested from the environment variable
# proceed the test command with TEST_BACKEND='django' | 'sqlalchemy'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply prepend the test command by TEST_BACKEND='django' or TEST_BACKEND='sqlalchemy'

ltalirz
ltalirz previously approved these changes Oct 20, 2017
Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!
Now we need to add a test to the aiida plugin template!

@DropD DropD merged commit e81cca4 into aiidateam:develop Oct 20, 2017
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.

None yet

2 participants