Skip to content

Commit

Permalink
tests: remove PytestDeprecationWarning
Browse files Browse the repository at this point in the history
* replace @pytest.yield_fixture with @pytest.fixture
  • Loading branch information
utnapischtim authored and slint committed Feb 19, 2024
1 parent 2a74f21 commit 0b079f8
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2015-2018 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -13,12 +14,13 @@

import sys

import celery._state
import pytest
from celery import Celery, shared_task
from flask import Flask


@pytest.yield_fixture()
@pytest.fixture()
def app(request):
"""Flask app fixture."""
app = Flask("testapp")
Expand All @@ -38,22 +40,22 @@ def shared_compute():
"""Dummy function."""
pass

yield app

import celery._state

celery._state._apps.discard(
app.extensions["invenio-celery"].celery._get_current_object()
)
celery._state._on_app_finalizers = set()
celery._state.set_default_app(Celery())

# Clear our modules to get them re-imported by Celery.
pkgs = [
"bpackage.first_tasks",
"bpackage.second_tasks",
"apackage.third_tasks",
]
for pkg in pkgs:
if pkg in sys.modules:
del sys.modules[pkg]
def set_celery_state():
celery._state._apps.discard(
app.extensions["invenio-celery"].celery._get_current_object()
)
celery._state._on_app_finalizers = set()
celery._state.set_default_app(Celery())

# Clear our modules to get them re-imported by Celery.
pkgs = [
"bpackage.first_tasks",
"bpackage.second_tasks",
"apackage.third_tasks",
]
for pkg in pkgs:
if pkg in sys.modules:
del sys.modules[pkg]

request.addfinalizer(set_celery_state)
return app

0 comments on commit 0b079f8

Please sign in to comment.