Skip to content

lundberg/pytest-httpx2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytest-HTTPX2

A pytest plugin for mocking out HTTPX2 using RESPX.

Install

Install with pip, or your favourite package manager:

pip install pytest-httpx2

Enable the pytest plugin and mock fixture, e.g. in your pyproject.toml:

[tool.pytest]
addopts = ["-p pytest_httpx2"]

Usage

import httpx2

def test_foobar(httpx2_mock: respx.Router) -> None:
    httpx2_mock.post("https://example.com/foobar").respond(201)
    response = httpx2.post("https://example.com/foobar")
    assert response.status_code == 201

Settings

Configure the httpx2_mock fixture with the included marker:

import pytest
import httpx2

@pytest.mark.httpx2(base_url="https://example.com")
def test_hamspam(httpx2_mock: respx.Router) -> None:
    httpx2_mock.get("/hamspam").respond(json={"id": 1337})
    response = httpx2.get("https://example.com/hamspam")
    assert response.status_code == 200
    assert response.json() == {"id": 1337}

See respx documentation for more configuration options and api.

About

A pytest plugin for mocking out httpx2 using respx 🦋

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors