Skip to main content

A pytest plugin to record HTTP(S) requests with stack trace.

Project description

pytest-httpdbg

A pytest plugin to record HTTP(S) requests with stack trace.

installation

pip install pytest-httpdbg

usage

pytest custom options

  --httpdbg             record HTTP(S) requests
  --httpdbg-dir=HTTPDBG_DIR
                        save httpdbg traces in a directory
  --httpdbg-no-clean    do not clean the httpdbg directory
  --httpdbg-initiator=HTTPDBG_INITIATOR
                        add a new initiator (package) for httpdbg

option httpdbg

Enables the record of the HTTP requests.

option httpdbg-dir

Indicates where to save the log files.

option httpdbg-no-clean

Does not clean existing log files if the log directory is not empty.

option http-initiator

An initiator is the function/method that is at the origin of the HTTP requests. By default, we already support some packages but you can add your own initiators.

To add a new package in the list of initiators, you can use the http-initiator command line argument.

You can use any package as an initiator, this is not limited to HTTP requests.

test report

When the test is finished (teardown step included), one log file in markdown format is written. The path to this log file is stashed in the item when the test starts (before the setup step), even if the file not exists yet.

pytest-html

You can copy the following code in your top-level conftest.py to include the logs into your pytest-html report.

import os

import pytest

from pytest_httpdbg import httpdbg_record_filename


@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(item, call):
    pytest_html = item.config.pluginmanager.getplugin("html")
    outcome = yield
    report = outcome.get_result()
    extras = getattr(report, "extras", [])

    if call.when == "call":
        if httpdbg_record_filename in item.stash:
            extras.append(
                pytest_html.extras.url(
                    os.path.basename(item.stash[httpdbg_record_filename]),
                    name="HTTPDBG",
                )
            )
            report.extras = extras

This example works if you use the same directory for the html test report file and the httpdbg logs.

pytest demo/ --httpdbg --httpdbg-dir report --html=report/report.html

If this is not the case, you must adapt it to your configuration.

documentation

https://httpdbg.readthedocs.io/en/latest/pytest/

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_httpdbg-0.7.0.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

pytest_httpdbg-0.7.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_httpdbg-0.7.0.tar.gz.

File metadata

  • Download URL: pytest_httpdbg-0.7.0.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pytest_httpdbg-0.7.0.tar.gz
Algorithm Hash digest
SHA256 dd887f410e0dbbdfa00387225de0ced9faf4b1b02d25b30d7df259ec1c88f02d
MD5 500423a94cb5ccaf4c6d88c93de8a39a
BLAKE2b-256 ac4ac3ce768df21ff2496e86287bfa43d8ce04061bcf440cd038228e2e4c0ddb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_httpdbg-0.7.0.tar.gz:

Publisher: build.yml on cle-b/pytest-httpdbg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_httpdbg-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_httpdbg-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f4102174a5c17ad8e985971e52d1439d46ae6750287dc69919daba267292838
MD5 db32dfcc5501eb0ced613686ea3eb326
BLAKE2b-256 25d5b2974245fe274565b9fcb1ca15cc2a781e43ceb42b93bd40eb83a288012c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_httpdbg-0.7.0-py3-none-any.whl:

Publisher: build.yml on cle-b/pytest-httpdbg

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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