Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/tests/conftest.py
import os | import os | ||||
import pytest | import pytest | ||||
import glob | import glob | ||||
from datetime import timedelta | from datetime import timedelta | ||||
import swh.scheduler.celery_backend.config | |||||
# this import is needed here to enforce creation of the celery current app | |||||
# BEFORE the swh_app fixture is called, otherwise the Celery app instance from | |||||
# celery_backend.config becomes the celery.current_app | |||||
from swh.core.utils import numfile_sortkey as sortkey | from swh.core.utils import numfile_sortkey as sortkey | ||||
from swh.scheduler import get_scheduler | from swh.scheduler import get_scheduler | ||||
from swh.scheduler.tests import SQL_DIR | from swh.scheduler.tests import SQL_DIR | ||||
DUMP_FILES = os.path.join(SQL_DIR, '*.sql') | DUMP_FILES = os.path.join(SQL_DIR, '*.sql') | ||||
# celery tasks for testing purpose; tasks themselves should be | # celery tasks for testing purpose; tasks themselves should be | ||||
# in swh/scheduler/tests/celery_tasks.py | # in swh/scheduler/tests/celery_tasks.py | ||||
Show All 28 Lines | return { | ||||
} | } | ||||
# override the celery_session_app fixture to monkeypatch the 'main' | # override the celery_session_app fixture to monkeypatch the 'main' | ||||
# swh.scheduler.celery_backend.config.app Celery application | # swh.scheduler.celery_backend.config.app Celery application | ||||
# with the test application. | # with the test application. | ||||
@pytest.fixture(scope='session') | @pytest.fixture(scope='session') | ||||
def swh_app(celery_session_app): | def swh_app(celery_session_app): | ||||
import swh.scheduler.celery_backend.config | |||||
swh.scheduler.celery_backend.config.app = celery_session_app | swh.scheduler.celery_backend.config.app = celery_session_app | ||||
yield celery_session_app | yield celery_session_app | ||||
@pytest.fixture | @pytest.fixture | ||||
def swh_scheduler(request, postgresql_proc, postgresql): | def swh_scheduler(request, postgresql_proc, postgresql): | ||||
scheduler_config = { | scheduler_config = { | ||||
'scheduling_db': 'postgresql://{user}@{host}:{port}/{dbname}'.format( | 'db': 'postgresql://{user}@{host}:{port}/{dbname}'.format( | ||||
host=postgresql_proc.host, | host=postgresql_proc.host, | ||||
port=postgresql_proc.port, | port=postgresql_proc.port, | ||||
user='postgres', | user='postgres', | ||||
dbname='tests') | dbname='tests') | ||||
} | } | ||||
all_dump_files = sorted(glob.glob(DUMP_FILES), key=sortkey) | all_dump_files = sorted(glob.glob(DUMP_FILES), key=sortkey) | ||||
Show All 18 Lines |