Skip to content
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
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
strategy:
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
broker: ['rmq', 'zmq']

services:
postgres:
Expand All @@ -55,4 +56,4 @@ jobs:
- name: Run pytest
env:
AIIDA_WARN_v3: 1
run: hatch test -v -- -s
run: hatch test -v -- -s --broker-backend ${{ matrix.broker }}
5 changes: 3 additions & 2 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
strategy:
matrix:
python-version: ['3.10', '3.14']
broker: ['rmq', 'zmq']

services:
postgres:
Expand All @@ -45,13 +46,13 @@ jobs:
- name: Install Python dependencies (with aiida-core@main)
id: install
run: |
uv pip install -e .[tests] aiida-core[atomic_tools]@git+https://github.com/aiidateam/aiida-core@main
uv pip install -e .[tests] aiida-core[atomic_tools]@git+https://github.com/agoscinski/aiida-core@fix/datetime-serialize

- name: Run pytest
id: tests
env:
AIIDA_WARN_v3: 1
run: pytest -sv tests
run: pytest -sv tests --broker-backend ${{ matrix.broker }}

- name: Slack notification
if: always() && (steps.install.outcome == 'failure' || steps.tests.outcome == 'failure') && env.SLACK_WEBHOOK != null
Expand Down
34 changes: 34 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,47 @@
import pathlib
import shutil
import tempfile
import time
from collections.abc import Mapping
from pathlib import Path

import pytest

pytest_plugins = ['aiida.tools.pytest_fixtures']

BROKER_BACKENDS = {
'rmq': 'core.rabbitmq',
'zmq': 'core.zeromq',
}


def pytest_addoption(parser):
"""Register the ``--broker-backend`` option to select the message broker used by the test profile."""
parser.addoption(
'--broker-backend',
action='store',
default='rmq',
choices=tuple(BROKER_BACKENDS),
help='Broker backend for the test profile: `rmq` (RabbitMQ, default) or `zmq` (ZeroMQ).',
)

@pytest.fixture(scope='session', autouse=True)
def aiida_profile(pytestconfig, aiida_config, aiida_profile_factory, run_aiida_broker_service_for_profile):
"""Load a temporary profile whose broker backend is selected through the ``--broker-backend`` option.

This overrides the ``aiida_profile`` fixture provided by ``aiida-core``, which loads a profile without any broker.
The broker backend defaults to RabbitMQ (``core.rabbitmq``) and can be switched to ZeroMQ (``core.zeromq``), which
requires no external service, via the ``--broker-backend`` command line option.

Several tests build an in-process runner that requires a communicator connected to the broker. Unlike RabbitMQ,
the ZeroMQ broker is not an external service but is launched by the daemon (through ``circus``). The daemon is
therefore started for the duration of the session when the ZeroMQ backend is selected, so that the broker is
available to the in-process runner, and stopped again at the end.
"""
broker_backend = BROKER_BACKENDS[pytestconfig.getoption('--broker-backend')]

with aiida_profile_factory(aiida_config, broker_backend=broker_backend) as profile:
yield profile

@pytest.fixture(scope='session', autouse=True)
def clean_asyncio_tasks():
Expand Down
Loading