Skip to content

Writing tests

Atsushi Togo edited this page Dec 7, 2021 · 23 revisions

Tests are written using pytest.

aiida-vasp pytest infrastructure

Automatic set-up of a temporary aiida-profile.

aiida_profile fixture is defined in aiida-core with scope='session' and returns an instance of TestManager class in aiida-core. aiida_profile is usually invisible from aiida-vasp test users, but automatically activated by @pytest.fixture(scope='session', autouse=True). In aiida-vasp, aiida_profile is activated in conftest.py via pytest_plugins that imports aiida-core's pytest_fixtures.py (see conftest.py).

fresh_aiida_env

This is used like @pytest.mark.usefixtures('fresh_aiida_env'). This fixture gets aiida_profile fixture by fresh_aiida_env(aiida_profile). The job of fresh_aiida_env is to reset aiida-profile DB after using it.

mock_vasp

mock_vasp is a mock of aiida code of VASP. The details may be found at aiida_vasp.utils.fixtures.data::_mock_vasp. Shortly, _mock_vasp returns an aiida-vasp vasp.vasp plugin code. In the returned code, the path to mock-vasp command is set as the "Remote absolute path". The mock-vasp command (aiida_vasp.commands.mock_vasp::mock_vasp -> @click.command('mock-vasp')) is installed in the process of aiida-vasp installation.

Additional information about click:

Pytest fixtures

Location:

  • aiida_vasp.utils.fixtures
  • aiida_vasp.parsers.tests.test_vasp_parser

Some important fixtures are shown below shortly.

calc_with_retrieved

A function that returns VaspCalculation node. More specifically, this function gets a folder path (FolderData) and input settings (Dict), stores them in temporary DB, makes them linked to the node, and finally returns the node.

vasp_parser_with_test

VaspParser instance with the node given by the fixture calc_with_retrieved. The folder path and settings are set in _get_vasp_parser(calc_with_retrieved).