Skip to main content

A module to simplify using pytest for AiiDA plugins.

Project description

NOTE: The aiida-pytest package is in maintenance mode: bugs will continue to be fixed for the foreseeable future, but no new features will be implemented. Users considering using aiida-pytest are strongly encouraged to use the built-in AiiDA fixtures instead.

aiida-pytest

This is a helper to enable testing AiiDA plugins with pytest. The main purpose is to create a fixture which sets up a temporary AiiDA database and user, and simplify setting up the computers and calculations.

To get started, create a tests folder where your pytest tests will be located. In conftests.py, you need to write

from aiida_pytest import *

This defines the configure and configure_with_daemon fixtures. To set up computers and codes for the test run, you need a config.yml file in the tests folder (and run pytest from there). The following example config file sets up localhost and the bands-inspect code:

computers:
  localhost:
    hostname: localhost
    description: localhost
    transport: local
    scheduler: direct
    work_directory: /tmp/test_aiida
    prepend_text: 'unset PYTHONPATH'

codes:
  bands_inspect:
    description: bands_inspect code
    default_plugin: bands_inspect.difference
    remote_computer: localhost
    remote_abspath: /home/a-dogres/.virtualenvs/bands-inspect/bin/bands-inspect

Note: aiida-pytest is not compatible with the aiida-xdist plugin, since the fixtures with scope=session are then called for each running worker.

Defining and running tests

Tests with aiida-pytest are defined and run exactly like "regular" pytest tests. If a test needs the AiiDA database, it should use the configure fixture. If the test also requires the Daemon to run, it should use the configure_with_daemon fixture. Note that, since certain AiiDA import statements require the database backend to be set, these imports should be done inside the test function.

After the tests have run, the code will wait for you to press Enter before deleting the testing database and repository. This gives you the opportunity to manually inspect the final state. If you want to avoid this step (for example in a CI system), pass the --quiet-wipe flag to py.test.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiida-pytest-0.1.0a7.tar.gz (6.9 kB view details)

Uploaded Source

File details

Details for the file aiida-pytest-0.1.0a7.tar.gz.

File metadata

  • Download URL: aiida-pytest-0.1.0a7.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for aiida-pytest-0.1.0a7.tar.gz
Algorithm Hash digest
SHA256 a97ce4eb32df3a8fadb1e733b097d1bbd39722da6a3c6ace16a8648038d8a25e
MD5 e4d593619470be2ba7e9c7ce23c5c7e2
BLAKE2b-256 bf76699a9fd1c8d9630a1f6171a4a0ab868710ae7d6a4c26fbef03b9ebb06423

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page