File: plugin.py

package info (click to toggle)
python-respx 0.22.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 868 kB
  • sloc: python: 4,379; makefile: 17
file content (30 lines) | stat: -rw-r--r-- 676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from typing import cast

import pytest

import respx

from .router import MockRouter


def pytest_configure(config):
    config.addinivalue_line(
        "markers",
        "respx(assert_all_called=False, assert_all_mocked=False, base_url=...): "
        "configure the respx_mock fixture. "
        "See https://lundberg.github.io/respx/api.html#configuration",
    )


@pytest.fixture
def respx_mock(request):
    respx_marker = request.node.get_closest_marker("respx")

    mock_router: MockRouter = (
        respx.mock
        if respx_marker is None
        else cast(MockRouter, respx.mock(**respx_marker.kwargs))
    )

    with mock_router:
        yield mock_router