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

Use new pytest fixtures with SQLite #79

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions aiida_test_cache/mock_code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@
"testing_config_action",
)

# ensure aiida's pytest plugin is loaded, which we rely on
pytest_plugins = ['aiida.manage.tests.pytest_fixtures']
# Load aiida's pytest fixtures
# For aiida-core>=2.6 we load new fixtures which use sqlite backend.
# WARNING: It's not clear what happens if the user later loads
# the old fixtures as well.
from aiida import __version__ as aiida_version
from packaging.version import Version

if Version(aiida_version) >= Version('2.6.0'):
aiida_core_fixtures = 'aiida.tools.pytest_fixtures'
else:
aiida_core_fixtures = 'aiida.manage.tests.pytest_fixtures'
pytest_plugins = [aiida_core_fixtures]
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ keywords = [
urls = {Homepage = "https://aiida-testing.readthedocs.io/"}
requires-python = ">=3.9"
dependencies = [
"aiida-core>=2.1,<2.6",
"aiida-core>=1.0.0,<3",
"pytest>=7.0",
"voluptuous~=0.12",
"packaging>=21.0",
]

[project.optional-dependencies]
Expand Down
18 changes: 10 additions & 8 deletions tests/archive_cache/test_archive_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ def _check_diff_workchain(res, node, should_have_used_cache=True):
#### tests


def test_create_node_archive(mock_code_factory, generate_diff_inputs, clear_database, tmp_path):
def test_create_node_archive(
aiida_profile_clean, mock_code_factory, generate_diff_inputs, tmp_path
):
"""
Basic test of the create node archive fixture functionality,
runs diff workchain and creates archive, check if archive was created
Expand Down Expand Up @@ -110,7 +112,7 @@ def test_create_node_archive(mock_code_factory, generate_diff_inputs, clear_data
assert os.path.isfile(archive_path)


def test_load_node_archive(clear_database, absolute_archive_path):
def test_load_node_archive(aiida_profile_clean, absolute_archive_path):
"""Basic test of the load node archive fixture functionality, check if archive is loaded"""

full_archive_path = absolute_archive_path('diff_workchain.tar.gz')
Expand All @@ -124,7 +126,7 @@ def test_load_node_archive(clear_database, absolute_archive_path):
assert n_nodes == 9


def test_mock_hash_codes(mock_code_factory, clear_database, liberal_hash):
def test_mock_hash_codes(aiida_profile_clean, mock_code_factory, liberal_hash):
"""test if mock of _get_objects_to_hash works for Code and Calcs"""

mock_code = mock_code_factory(
Expand All @@ -144,15 +146,15 @@ def test_mock_hash_codes(mock_code_factory, clear_database, liberal_hash):
]
)
def test_enable_archive_cache(
archive_path, aiida_local_code_factory, generate_diff_inputs, enable_archive_cache,
clear_database, check_diff_workchain
archive_path, aiida_profile_clean, aiida_code_installed, generate_diff_inputs,
enable_archive_cache, check_diff_workchain
):
"""
Basic test of the enable_archive_cache fixture
"""

inputs = {'diff': generate_diff_inputs()}
diff_code = aiida_local_code_factory(executable='diff', entry_point='diff')
diff_code = aiida_code_installed(filepath_executable='diff')
diff_code.store()
inputs['diff']['code'] = diff_code
with enable_archive_cache(archive_path, calculation_class=CalculationFactory(CALC_ENTRY_POINT)):
Expand All @@ -162,7 +164,7 @@ def test_enable_archive_cache(


def test_enable_archive_cache_non_existent(
aiida_local_code_factory, generate_diff_inputs, enable_archive_cache, clear_database,
aiida_profile_clean, aiida_code_installed, generate_diff_inputs, enable_archive_cache,
tmp_path_factory, check_diff_workchain
):
"""
Expand All @@ -171,7 +173,7 @@ def test_enable_archive_cache_non_existent(
"""

inputs = {'diff': generate_diff_inputs()}
diff_code = aiida_local_code_factory(executable='diff', entry_point='diff')
diff_code = aiida_code_installed(filepath_executable='diff')
diff_code.store()
inputs['diff']['code'] = diff_code

Expand Down
Loading