Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/tests/conftest.py
- This file was added.
# Copyright (C) 2022 The Software Heritage developers | |||||
# See the AUTHORS file at the top-level directory of this distribution | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
from _pytest.monkeypatch import MonkeyPatch | |||||
anlambert: You should not import stuffs from private modules, we already have some issues because of that… | |||||
import pytest | |||||
from swh.graphql import server as app_server | |||||
from swh.storage import get_storage as get_swhstorage | |||||
from .data import populate_dummy_data | |||||
@pytest.fixture(scope="session") | |||||
def sessionmonkeypatch(*args, **kw): | |||||
sessionpatch = MonkeyPatch() | |||||
yield sessionpatch | |||||
sessionpatch.undo() | |||||
@pytest.fixture(scope="session") | |||||
def storage(sessionmonkeypatch): | |||||
def mock_storage(*args, **kw): | |||||
storage = get_swhstorage(cls="memory") | |||||
populate_dummy_data(storage) | |||||
return storage | |||||
sessionmonkeypatch.setattr(app_server, "get_storage", mock_storage) | |||||
anlambertUnsubmitted Done Inline ActionsUse pytest-mock instead, this should translate to: @pytest.fixture(scope="session") def storage(mocker): def mock_storage(*args, **kw): storage = get_swhstorage(cls="memory") populate_dummy_data(storage) return storage mocker.patch.object(app_server, "get_storage", mock_storage) anlambert: Use [pytest-mock](https://pypi.org/project/pytest-mock/) instead, this should translate to… | |||||
anlambertUnsubmitted Done Inline ActionsOk got it, you were forced to proceed like this because of the session scope. I think you can use function scope fixture (the default) directly then, based on my This way you can directly use the monkeypatch fixture. anlambert: Ok got it, you were forced to proceed like this because of the session scope.
I think you can… | |||||
jayeshvAuthorUnsubmitted Done Inline ActionsRemoved this mock, setting the global variable directly from conftest. jayeshv: Removed this mock, setting the global variable directly from conftest. | |||||
@pytest.fixture(scope="session") | |||||
def client(storage): | |||||
app = app_server.make_app_from_configfile("config/test.yml") | |||||
with app.test_client() as client: | |||||
yield client |
You should not import stuffs from private modules, we already have some issues because of that in the past.