A pytest plugin to record HTTP(S) requests with stack trace.
Project description
pytest-httpdbg
A pytest plugin for recording HTTP(S) requests and saving them in your test report.
installation
pip install pytest-httpdbg
Allure report
If you use the allure-pytest plugin to generate an Allure report, you can use pytest-httpdbg to include HTTP request traces in your test report without any code modifications.
All you need to do is add the --httpdbg-allure option to your pytest command line:
pytest ../httpdbg-docs/examples/ --alluredir=./allure-results --httpdbg-allure
If an HTTP request is made by the test (or within a fixture, during the setup or teardown phase), the request will be saved in the Allure report under a step called httpdbg.
Custom test report
You can add HTTP traces to any test report of your choice. To do this, you can use the HTTP traces saved by the plugin in Markdown format.
When a test finishes (including the teardown step), a log file in Markdown format is generated. The path to this log file is stored in the test item when the test starts (before the setup step), even if the file does not yet exist.
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.
pytest command line options
reporting:
--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-allure save HTTP(S) traces into the allure report
--httpdbg-no-headers do not save the HTTP headers
--httpdbg-no-binary do not save the HTTP payload if it's a binary content
--httpdbg-only-on-failure save the HTTP requests only if the test failed
--httpdbg-initiator=HTTPDBG_INITIATOR add a new initiator (package) for httpdbg
httpdbg
This plugin is based on the httpdbg Python tool. You can use it to trace all HTTP requests in your tests and view them in a more detailed user interface using the pyhttpdbg command.
pyhttpdbg -m pytest -v examples/
documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_httpdbg-0.9.1.tar.gz.
File metadata
- Download URL: pytest_httpdbg-0.9.1.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6cab9672f7798cbfdcffd85605fbaa74830884c728539519e38fe37add2dffc
|
|
| MD5 |
5eca3e4e176dfe975d3cdb2e6a3bc8b6
|
|
| BLAKE2b-256 |
246f2495dd87d7de912c78cfc60e04fa88d745335801233f5ca4e459ec9384b0
|
Provenance
The following attestation bundles were made for pytest_httpdbg-0.9.1.tar.gz:
Publisher:
build.yml on cle-b/pytest-httpdbg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_httpdbg-0.9.1.tar.gz -
Subject digest:
a6cab9672f7798cbfdcffd85605fbaa74830884c728539519e38fe37add2dffc - Sigstore transparency entry: 585793042
- Sigstore integration time:
-
Permalink:
cle-b/pytest-httpdbg@26c4368fbffc565f24f80831624e2b06e58f70d6 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/cle-b
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@26c4368fbffc565f24f80831624e2b06e58f70d6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_httpdbg-0.9.1-py3-none-any.whl.
File metadata
- Download URL: pytest_httpdbg-0.9.1-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cb3840c04c264dc02f00fc925f325010b1ced09337f5d2d52c41d65f01ce1eb
|
|
| MD5 |
81390da90e63937e17082005dc32f33c
|
|
| BLAKE2b-256 |
cdef61aa16dac1b513d3cfe3d63cf285b2c10c2595835f9cee73685baba7b043
|
Provenance
The following attestation bundles were made for pytest_httpdbg-0.9.1-py3-none-any.whl:
Publisher:
build.yml on cle-b/pytest-httpdbg
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_httpdbg-0.9.1-py3-none-any.whl -
Subject digest:
0cb3840c04c264dc02f00fc925f325010b1ced09337f5d2d52c41d65f01ce1eb - Sigstore transparency entry: 585793051
- Sigstore integration time:
-
Permalink:
cle-b/pytest-httpdbg@26c4368fbffc565f24f80831624e2b06e58f70d6 -
Branch / Tag:
refs/tags/v0.9.1 - Owner: https://github.com/cle-b
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build.yml@26c4368fbffc565f24f80831624e2b06e58f70d6 -
Trigger Event:
push
-
Statement type: