pytest-monitor
raw JSON → 1.6.6 verified Mon Apr 27 auth: no python
A pytest plugin for analyzing resource usage (CPU, memory, I/O) of tests. It records resource consumption and optionally sends results to a monitoring server. The current version is 1.6.6, with a maintenance cadence of a few releases per year.
pip install pytest-monitor Common errors
error ModuleNotFoundError: No module named 'pytest_monitor' ↓
cause The user tries to import pytest_monitor explicitly but the package may not be installed or they missed the underscore.
fix
Install with 'pip install pytest-monitor'. The import is not needed; the plugin is auto-discovered.
error pytest: error: unrecognized arguments: --monitor ↓
cause Using --monitor flag without the plugin installed or activated.
fix
Ensure pytest-monitor is installed (pip list | grep pytest-monitor) and that you are running pytest from the correct environment.
error pytest_monitor.plugin.MonitoringException: Unable to retrieve CPU frequency ↓
cause psutil fails to get CPU frequency on some systems.
fix
Set the environment variable CPU_FREQUENCY to your CPU's frequency in MHz (e.g., export CPU_FREQUENCY=2400) or upgrade to 1.6.5+ where a fallback is handled.
Warnings
breaking Version 1.6.6 is the last to support Python 3.6 and older, and pytest 5.* and older. ↓
fix Upgrade Python to >=3.7 and pytest to >=6.0 when moving beyond 1.6.6.
deprecated The option --send-results has been renamed to --monitor-server to avoid collisions on Windows. ↓
fix Use --monitor-server instead of --send-results.
gotcha Doctests cause pytest-monitor to crash if monitoring is enabled. The plugin now automatically disables monitoring for doctests, but older versions may fail. ↓
fix Upgrade to 1.6.0 or later, or exclude doctests from monitoring.
gotcha If psutil cannot fetch CPU frequency, the plugin may crash. Set environment variable CPU_FREQUENCY to a fallback value. ↓
fix Set CPU_FREQUENCY env var (e.g., export CPU_FREQUENCY=2400) or upgrade to 1.6.5+ if possible.
Imports
- pytest_monitor
import pytest_monitor
Quickstart
# pytest automatically discovers and activates the plugin
# Install: pip install pytest-monitor
# Run tests with resource monitoring enabled by default
# Example test file: test_example.py
def test_resource_usage():
import time
time.sleep(0.1)
assert True
# Run: pytest --monitor=sqlite:///monitor.db test_example.py