Skip to main content
PyPI version Python versions See Build Status on GitHub Actions

Use MITM Proxy in autotests with full control from code


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features

  • You can control the traffic flow dynamically: add or remove addons during the test, modify content on a fly

  • Proxy thread is starting only once per session, but only if test requested the proxy - you can save extra time in both ways - no extra creating proxies, no extra recreating as well

  • Don’t think about addons after the test - by default, all addons ill be removed right after test ending

  • Use default 0-port to avoid port allocating conflict or set an exact one in the settings

Requirements

  • There is no extra requirements to use this package. But you still need to install/provide path to MITMProxy certificates to work with HTTPS

Installation

You can install “pytest-mitmproxy-plugin” via pip from PyPI:

$ pip install pytest-mitmproxy-plugin

Usage

All communication is based on MitmManager wrapper - mitm_manager fixture provides such wrapper right into the test. The MitmManager is designed to creating on-demand once per test session, but after each test all added addon are flushed.

Each interaction with traffic require creating a MITMProxy addon - you can read more about addons on the official page - https://docs.mitmproxy.org/stable/addons-overview/ You may add several addons at once using .add_addon method or remove exact or all addons by .delete_addon or .delete_all_addons. Each addon should inherit the AbstractAddon, although it will work without it, it makes code more clear.

You can configure plugin params by using CLI arguments or pyproject.toml. CLI arguments always have a priority. Next options are configurable:

–proxy-mode ( or mode in .toml ) - string, take a look onto MitmMode enum or CLI help, you may choose, which mode is better for you. By default plugin use SOCKS5, but you may find HTTP ( regular ) more convenient in your case

–proxy-host ( or host in .toml ) - string, usually just 127.0.0.1 ( default ) or 0.0.0.0

–proxy-port ( or port in .toml ) - number, zero by default ( which means “take an empty port” ) or any other port on machine

–proxy-log-level ( or log_level in .toml ) - string, log level according logging, by default - INFO

–proxy-log-dir-path ( or log_dir_path in .toml ) - by default, MITMProxy send info data right into stdout, but sometimes in is better to capture in separately, log files will be created in directory

The toml configuration should be under “mitmproxy-plugin” label, full configration example:

[mitmproxy-plugin]
mode = "socks5"
host = "127.0.0.1"
port = 0
log_level = "INFO"

Version convention

The major version define significant changes, which may not have the backward compatibility. The patch version define changes, which modify plugin code, but have the backward compatibility. The minor version changes define internal changes like workflow/linters etc.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-mitmproxy-plugin” is free and open source software

Issues

If you encounter any problems, please file an issue along with a detailed description.

Metadata

Release files for pytest-mitmproxy-plugin 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-mitmproxy-plugin 0.1.0
File Size Uploaded
pytest_mitmproxy_plugin-0.1.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pytest-mitmproxy-plugin 0.1.0
File Interpreter ABI Platform
pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / pytest_mitmproxy_plugin-0.1.0.tar.gz

Download URL pytest_mitmproxy_plugin-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
446cda84d3f3be19515eb3c21ff0f7e499208b479a40b053b538509c316cfabb
BLAKE2b-256 checksum
How to use checksums
71d048ff90f2ad6664ff62ebbdc4d8b38057b14843d701f471a3883f38757a76
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 10, 2025.

Transparency log

Release files / pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl

Download URL pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2a0414091ad692530d258bfa0a4061e0e179ca97ae3c9a5f452eba012aaed03a
BLAKE2b-256 checksum
How to use checksums
c079a0e14d7e24218a3e7edb18ea54e5079a0cd422558963aa464ee2ac033fac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 10, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page