Skip to content

Commit

Permalink
Allow multiple requests for single mocked URL
Browse files Browse the repository at this point in the history
For pytest-httpx.
While this is an opportunity to optimize (probably), this is considered
irrelevant for now.

Introduce configuration updates for pytest-asyncio when migrating from
v0.23.
  • Loading branch information
CasperWA committed Oct 1, 2024
1 parent 6265cee commit 9d1ea7f
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
env:
OPTIMADE_MONGO_URI: "mongodb://localhost:27017"
OPTIMADE_DATABASE_BACKEND: ${{ matrix.database-backend }}
run: pytest -vvv --cov-report=xml
run: pytest -vvv --cov-report=xml --color=yes

- name: Upload coverage to Codecov
if: github.repository == 'Materials-Consortia/optimade-gateway'
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ filterwarnings = [
"ignore:.*pkg_resources is deprecated as an API.*:DeprecationWarning",
]
asyncio_mode = "auto"
asyncio_default_fixture_loop_scope = "function"

[tool.ruff.lint]
extend-select = [
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import TYPE_CHECKING

import pytest
import pytest_asyncio

if TYPE_CHECKING:
from collections.abc import Awaitable
Expand Down Expand Up @@ -186,15 +187,15 @@ def pytest_configure(config: pytest.Config): # noqa: ARG001
# PYTEST FIXTURES


@pytest.fixture(scope="session")
@pytest_asyncio.fixture(loop_scope="session", scope="session")
def top_dir() -> Path:
"""Return Path instance for the repository's top (root) directory"""
from pathlib import Path

return Path(__file__).parent.parent.resolve()


@pytest.fixture(scope="session", autouse=True)
@pytest_asyncio.fixture(loop_scope="session", scope="session", autouse=True)
async def _setup_db(top_dir: Path) -> None:
"""Setup test DB"""
await setup_db_utility(top_dir)
Expand Down
2 changes: 2 additions & 0 deletions tests/queries/test_perform.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
if TYPE_CHECKING:
from pytest_httpx import HTTPXMock

pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)


async def test_db_get_all_resources_recursivity(
httpx_mock: HTTPXMock, generic_meta: dict
Expand Down
1 change: 1 addition & 0 deletions tests/routers/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ async def test_errored_query_results(
assert response.data.attributes.response.errors


@pytest.mark.httpx_mock(can_send_already_matched_responses=True)
async def test_sort_no_effect(
client: AsyncGatewayClient,
get_gateway: GetGateway,
Expand Down
3 changes: 3 additions & 0 deletions tests/routers/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from ..conftest import AsyncGatewayClient, GetGateway, MockGatewayResponses

pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)


async def test_get_search(
client: AsyncGatewayClient,
Expand Down Expand Up @@ -453,6 +455,7 @@ async def test_sort_no_effect(
)


@pytest.mark.httpx_mock(assert_all_requests_were_expected=False)
async def test_get_search_not_finishing(
client: AsyncGatewayClient,
mock_gateway_responses: MockGatewayResponses,
Expand Down
2 changes: 2 additions & 0 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from .conftest import GetGateway, MockGatewayResponses

pytestmark = pytest.mark.httpx_mock(can_send_already_matched_responses=True)


async def test_ci_dev_startup_ci(
caplog: pytest.LogCaptureFixture, top_dir: Path
Expand Down

0 comments on commit 9d1ea7f

Please sign in to comment.