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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file pytest_httpx_recorder-0.0.1.tar.gz.

File metadata

  • Download URL: pytest_httpx_recorder-0.0.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for pytest_httpx_recorder-0.0.1.tar.gz
Algorithm Hash digest
SHA256 3d491135b1b323ad1238416ab93617cf9c9e8782275c400a6f3b036f20d37545
MD5 da4410655cdf679397e4db176168fd83
BLAKE2b-256 d66fb46552db25809cdfca1ecb1c406646aa2c8de3158b458db7cc370fdc9989

See more details on using hashes here.

File details

Details for the file pytest_httpx_recorder-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_httpx_recorder-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b74ba86359a892d4acf0f79f31096bace65546b7f5107c3bc20dfb1022129d
MD5 b6e479890411af06191cbd23e42f976b
BLAKE2b-256 917fccadf9daa6bc17a5459181c2fda4c39a2d8d63b7cb9004eddfcc3198c9fb

See more details on using hashes here.

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