Skip to main content

Recorder feature based on pytest_httpx, like recorder feature in responses.

Project description

pytest_httpx_recorder

PyPI PyPI - Python Version Loc Comments

Code Test Package Release codecov

GitHub Org's stars GitHub stars GitHub forks GitHub commit activity GitHub issues GitHub pulls Contributors GitHub license

Recorder feature based on pytest_httpx, like recorder feature in responses

Installation

pip install pytest_httpx_recorder

For more information about installation, you can refer to Installation.

Record the Requests

import httpx

from pytest_httpx_recorder.recorder import ResRecorder

if __name__ == '__main__':
    recorder = ResRecorder()
    with recorder.record():
        client = httpx.Client(follow_redirects=True)
        client.get('https://danbooru.donmai.us/artists/167715.json')
        client.head(
            'https://cdn.donmai.us/original/9b/25/__akisato_konoha_uehara_meiko_shimoda_kaori_yamada_touya_rokuta_mamoru_and_4_more_comic_party_and_1_more__9b257058ee0866d554d01e9036ecb3b6.jpg')

    # save to directory 'test_danbooru_simple'
    recorder.to_resset().save('test_danbooru_simple')

Replay in Pytest

import httpx
import pytest

from pytest_httpx_recorder.recorder import ResSet


@pytest.fixture
def replay_from_test_danbooru_simple(httpx_mock):
    resset = ResSet.load('test_danbooru_simple')
    with resset.mock_context(httpx_mock):
        yield


def test_replay(replay_from_test_danbooru_simple):
    client = httpx.Client(follow_redirects=True)
    resp = client.get('https://danbooru.donmai.us/artists/167715.json')
    resp.raise_for_status()

    resp = client.head(
        'https://cdn.donmai.us/original/9b/25/__akisato_konoha_uehara_meiko_shimoda_kaori_yamada_touya_rokuta_mamoru_and_4_more_comic_party_and_1_more__9b257058ee0866d554d01e9036ecb3b6.jpg')
    resp.raise_for_status()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_httpx_recorder-0.0.1.tar.gz (13.3 kB view hashes)

Uploaded Source

Built Distribution

pytest_httpx_recorder-0.0.1-py3-none-any.whl (12.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page