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

🧪 TESTS: Add pytest requires_rmq marker #4739

Merged
merged 6 commits into from
Feb 10, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/rabbitmq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ jobs:
pip freeze

- name: Run tests
run: pytest -sv tests/manage/external/test_rmq.py
run: pytest -sv -k 'requires_rmq'
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ filterwarnings = [
"default::ResourceWarning",
]
markers = [
"requires_rmq: requires a connection (on port 5672) to RabbitMQ",
"sphinx: set parameters for the sphinx `app` fixture"
]

Expand Down
2 changes: 2 additions & 0 deletions tests/calculations/arithmetic/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from aiida.calculations.arithmetic.add import ArithmeticAddCalculation


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_add_default(fixture_sandbox, aiida_localhost, generate_calc_job):
"""Test a default `ArithmeticAddCalculation`."""
Expand Down Expand Up @@ -43,6 +44,7 @@ def test_add_default(fixture_sandbox, aiida_localhost, generate_calc_job):
assert input_written == f"echo $(({inputs['x'].value} + {inputs['y'].value}))\n"


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_add_custom_filenames(fixture_sandbox, aiida_localhost, generate_calc_job):
"""Test an `ArithmeticAddCalculation` with non-default input and output filenames."""
Expand Down
2 changes: 2 additions & 0 deletions tests/calculations/test_templatereplacer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from aiida.common import datastructures


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_base_template(fixture_sandbox, aiida_localhost, generate_calc_job):
"""Test a base template that emulates the arithmetic add."""
Expand Down Expand Up @@ -70,6 +71,7 @@ def test_base_template(fixture_sandbox, aiida_localhost, generate_calc_job):
assert input_written == f"echo $(({inputs['parameters']['x']} + {inputs['parameters']['y']}))"


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_file_usage(fixture_sandbox, aiida_localhost, generate_calc_job):
"""Test a base template that uses two files."""
Expand Down
3 changes: 3 additions & 0 deletions tests/calculations/test_transfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from aiida.common import datastructures


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_get_transfer(fixture_sandbox, aiida_localhost, generate_calc_job, tmp_path):
"""Test a default `TransferCalculation`."""
Expand Down Expand Up @@ -64,6 +65,7 @@ def test_get_transfer(fixture_sandbox, aiida_localhost, generate_calc_job, tmp_p
assert sorted(calc_info.retrieve_list) == sorted(retrieve_list)


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_put_transfer(fixture_sandbox, aiida_localhost, generate_calc_job, tmp_path):
"""Test a default `TransferCalculation`."""
Expand Down Expand Up @@ -199,6 +201,7 @@ def test_validate_transfer_inputs(aiida_localhost, tmp_path, temp_dir):
assert result == expected


@pytest.mark.requires_rmq
def test_integration_transfer(aiida_localhost, tmp_path):
"""Test a default `TransferCalculation`."""
from aiida.calculations.transfer import TransferCalculation
Expand Down
4 changes: 3 additions & 1 deletion tests/cmdline/commands/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
import unittest
import tempfile
import subprocess as sp
import numpy as np

from click.testing import CliRunner
import numpy as np
import pytest

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
Expand Down Expand Up @@ -229,6 +230,7 @@ def test_arrayshow(self):
self.assertEqual(res.exit_code, 0, 'The command did not finish correctly')


@pytest.mark.requires_rmq
class TestVerdiDataBands(AiidaTestCase, DummyVerdiDataListable):
"""Testing verdi data bands."""

Expand Down
4 changes: 3 additions & 1 deletion tests/cmdline/commands/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
from concurrent.futures import Future

from click.testing import CliRunner
import plumpy
import kiwipy
import plumpy
import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import cmd_process
Expand Down Expand Up @@ -63,6 +64,7 @@ def tearDown(self):
os.kill(self.daemon.pid, signal.SIGTERM)
super().tearDown()

@pytest.mark.requires_rmq
def test_pause_play_kill(self):
"""
Test the pause/play/kill commands
Expand Down
3 changes: 3 additions & 0 deletions tests/cmdline/commands/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import warnings

from click.testing import CliRunner
import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.cmdline.commands import cmd_run
Expand All @@ -25,6 +26,7 @@ def setUp(self):
super().setUp()
self.cli_runner = CliRunner()

@pytest.mark.requires_rmq
def test_run_workfunction(self):
"""Regression test for #2165

Expand Down Expand Up @@ -181,6 +183,7 @@ def test_no_autogroup(self):
all_auto_groups = queryb.all()
self.assertEqual(len(all_auto_groups), 0, 'There should be no autogroup generated')

@pytest.mark.requires_rmq
def test_autogroup_filter_class(self): # pylint: disable=too-many-locals
"""Check if the autogroup is properly generated but filtered classes are skipped."""
from aiida.orm import Code, QueryBuilder, Node, AutoGroup, load_node
Expand Down
1 change: 1 addition & 0 deletions tests/cmdline/commands/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from aiida.cmdline.utils.echo import ExitCode


@pytest.mark.requires_rmq
def test_status(run_cli_command):
"""Test `verdi status`."""
options = []
Expand Down
1 change: 1 addition & 0 deletions tests/engine/daemon/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from aiida.engine.daemon.runner import shutdown_runner


@pytest.mark.requires_rmq
@pytest.mark.asyncio
async def test_shutdown_runner(manager):
"""Test the ``shutdown_runner`` method."""
Expand Down
6 changes: 6 additions & 0 deletions tests/engine/processes/workchains/test_restart.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def test_get_process_handler():
assert [handler.__name__ for handler in SomeWorkChain.get_process_handlers()] == ['handler_a', 'handler_b']


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_excepted_process(generate_work_chain, generate_calculation_node):
"""Test that the workchain aborts if the sub process was excepted."""
Expand All @@ -58,6 +59,7 @@ def test_excepted_process(generate_work_chain, generate_calculation_node):
assert process.inspect_process() == engine.BaseRestartWorkChain.exit_codes.ERROR_SUB_PROCESS_EXCEPTED


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_killed_process(generate_work_chain, generate_calculation_node):
"""Test that the workchain aborts if the sub process was killed."""
Expand All @@ -67,6 +69,7 @@ def test_killed_process(generate_work_chain, generate_calculation_node):
assert process.inspect_process() == engine.BaseRestartWorkChain.exit_codes.ERROR_SUB_PROCESS_KILLED


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_unhandled_failure(generate_work_chain, generate_calculation_node):
"""Test the unhandled failure mechanism.
Expand All @@ -85,6 +88,7 @@ def test_unhandled_failure(generate_work_chain, generate_calculation_node):
) == engine.BaseRestartWorkChain.exit_codes.ERROR_SECOND_CONSECUTIVE_UNHANDLED_FAILURE # pylint: disable=no-member


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_unhandled_reset_after_success(generate_work_chain, generate_calculation_node):
"""Test `ctx.unhandled_failure` is reset to `False` in `inspect_process` after a successful process."""
Expand All @@ -99,6 +103,7 @@ def test_unhandled_reset_after_success(generate_work_chain, generate_calculation
assert process.ctx.unhandled_failure is False


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_unhandled_reset_after_handled(generate_work_chain, generate_calculation_node):
"""Test `ctx.unhandled_failure` is reset to `False` in `inspect_process` after a handled failed process."""
Expand All @@ -120,6 +125,7 @@ def test_unhandled_reset_after_handled(generate_work_chain, generate_calculation
assert process.ctx.unhandled_failure is False


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_run_process(generate_work_chain, generate_calculation_node, monkeypatch):
"""Test the `run_process` method."""
Expand Down
3 changes: 3 additions & 0 deletions tests/engine/processes/workchains/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
###########################################################################
# pylint: disable=no-self-use,unused-argument,unused-variable,function-redefined,missing-class-docstring,missing-function-docstring
"""Tests for `aiida.engine.processes.workchains.utils` module."""
import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.engine import ExitCode, ProcessState
from aiida.engine.processes.workchains.restart import BaseRestartWorkChain
Expand All @@ -19,6 +21,7 @@
ArithmeticAddCalculation = CalculationFactory('arithmetic.add')


@pytest.mark.requires_rmq
class TestRegisterProcessHandler(AiidaTestCase):
"""Tests for the `process_handler` decorator."""

Expand Down
8 changes: 8 additions & 0 deletions tests/engine/test_calc_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def raise_exception(exception):
raise exception()


@pytest.mark.requires_rmq
class FileCalcJob(CalcJob):
"""Example `CalcJob` implementation to test the `provenance_exclude_list` functionality.

Expand Down Expand Up @@ -72,6 +73,7 @@ def prepare_for_submission(self, folder):
return calcinfo


@pytest.mark.requires_rmq
class TestCalcJob(AiidaTestCase):
"""Test for the `CalcJob` process sub class."""

Expand Down Expand Up @@ -388,6 +390,7 @@ def _generate_process(inputs=None):
return _generate_process


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test', 'override_logging')
def test_parse_insufficient_data(generate_process):
"""Test the scheduler output parsing logic in `CalcJob.parse`.
Expand Down Expand Up @@ -418,6 +421,7 @@ def test_parse_insufficient_data(generate_process):
assert log in logs


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test', 'override_logging')
def test_parse_non_zero_retval(generate_process):
"""Test the scheduler output parsing logic in `CalcJob.parse`.
Expand All @@ -437,6 +441,7 @@ def test_parse_non_zero_retval(generate_process):
assert 'could not parse scheduler output: return value of `detailed_job_info` is non-zero' in logs


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test', 'override_logging')
def test_parse_not_implemented(generate_process):
"""Test the scheduler output parsing logic in `CalcJob.parse`.
Expand Down Expand Up @@ -466,6 +471,7 @@ def test_parse_not_implemented(generate_process):
assert log in logs


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test', 'override_logging')
def test_parse_scheduler_excepted(generate_process, monkeypatch):
"""Test the scheduler output parsing logic in `CalcJob.parse`.
Expand Down Expand Up @@ -501,6 +507,7 @@ def raise_exception(*args, **kwargs):
assert log in logs


@pytest.mark.requires_rmq
@pytest.mark.parametrize(('exit_status_scheduler', 'exit_status_retrieved', 'final'), (
(None, None, 0),
(100, None, 100),
Expand Down Expand Up @@ -568,6 +575,7 @@ def parse_retrieved_output(_, __):
assert result.status == final


@pytest.mark.requires_rmq
@pytest.mark.usefixtures('clear_database_before_test')
def test_additional_retrieve_list(generate_process, fixture_sandbox):
"""Test the ``additional_retrieve_list`` option."""
Expand Down
2 changes: 2 additions & 0 deletions tests/engine/test_calcfunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for the calcfunction decorator and CalcFunctionNode."""
import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.common import exceptions
Expand Down Expand Up @@ -37,6 +38,7 @@ def execution_counter_calcfunction(data):
return Int(data.value + 1)


@pytest.mark.requires_rmq
class TestCalcFunction(AiidaTestCase):
"""Tests for calcfunctions.

Expand Down
3 changes: 3 additions & 0 deletions tests/engine/test_futures.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@
"""Module to test process futures."""
import asyncio

import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.engine import processes, run
from aiida.manage.manager import get_manager

from tests.utils import processes as test_processes


@pytest.mark.requires_rmq
class TestWf(AiidaTestCase):
"""Test process futures."""
TIMEOUT = 5.0 # seconds
Expand Down
4 changes: 4 additions & 0 deletions tests/engine/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Module to test processess launch."""
import pytest

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
from aiida.common import exceptions
Expand Down Expand Up @@ -62,6 +64,7 @@ def add(self):
self.out('result', orm.Int(self.inputs.term_a + self.inputs.term_b).store())


@pytest.mark.requires_rmq
class TestLaunchers(AiidaTestCase):
"""Class to test process launchers."""

Expand Down Expand Up @@ -142,6 +145,7 @@ def test_submit_store_provenance_false(self):
launch.submit(AddWorkChain, term_a=self.term_a, term_b=self.term_b, metadata={'store_provenance': False})


@pytest.mark.requires_rmq
class TestLaunchersDryRun(AiidaTestCase):
"""Test the launchers when performing a dry-run."""

Expand Down
3 changes: 3 additions & 0 deletions tests/engine/test_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
###########################################################################
"""Test persisting via the AiiDAPersister."""
import plumpy
import pytest

from aiida.backends.testbase import AiidaTestCase
from aiida.engine.persistence import AiiDAPersister
Expand All @@ -17,6 +18,7 @@
from tests.utils.processes import DummyProcess


@pytest.mark.requires_rmq
class TestProcess(AiidaTestCase):
"""Test the basic saving and loading of process states."""

Expand All @@ -40,6 +42,7 @@ def test_save_load(self):
self.assertEqual(loaded_process.state, plumpy.ProcessState.FINISHED)


@pytest.mark.requires_rmq
class TestAiiDAPersister(AiidaTestCase):
"""Test AiiDAPersister."""
maxDiff = 1024
Expand Down
3 changes: 3 additions & 0 deletions tests/engine/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import plumpy
from plumpy.utils import AttributesFrozendict
import pytest

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
Expand All @@ -36,6 +37,7 @@ def define(cls, spec):
spec.input('some.name.space.a', valid_type=orm.Int)


@pytest.mark.requires_rmq
class TestProcessNamespace(AiidaTestCase):
"""Test process namespace"""

Expand Down Expand Up @@ -91,6 +93,7 @@ def on_stop(self):
assert self._thread_id is threading.current_thread().ident


@pytest.mark.requires_rmq
class TestProcess(AiidaTestCase):
"""Test AiiDA process."""

Expand Down
2 changes: 2 additions & 0 deletions tests/engine/test_process_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""Tests for the process_function decorator."""
import pytest

from aiida import orm
from aiida.backends.testbase import AiidaTestCase
Expand All @@ -22,6 +23,7 @@
CUSTOM_DESCRIPTION = 'Custom description'


@pytest.mark.requires_rmq
class TestProcessFunction(AiidaTestCase):
"""
Note that here we use `@workfunctions` and `@calculations`, the concrete versions of the
Expand Down
Loading