Registry / testing / pytest-otel

pytest-otel

JSON →
library2.2.1pypypi✓ verified 86d ago

OpenTelemetry plugin for Pytest that automatically traces test execution, fixtures, and assertions. Currently at version 2.2.1, with monthly releases following OpenTelemetry SDK updates.

pip install pytest-otel
INSTALL
IMPORT
SIG · PYTEST-OTEL
P
pytest-otel
testingpythonv2.2.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest_otel
import pytest_otel
from pytest_otel import otel
pytest-otel is a plugin, not a package with public API. Just import the package to register hooks.

After installing, the plugin hooks into pytest automatically. Set OpenTelemetry environment variables to configure exporters and service name.

# conftest.py import os import pytest_otel # The plugin activates automatically. To configure: # export OTEL_SERVICE_NAME=my-test-service # export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317 def test_example(): assert 1 + 1 == 2
Debug
Known issues
breakingIn v2.0.0, the plugin dropped support for Python 3.8 and refactored the hook internals. Custom spans from older versions may not work without migration.
fix
Upgrade to 2.2.1, remove any monkey-patching of internal methods, and ensure your OpenTelemetry SDK is >=1.20.
affects: <2.0.0
deprecatedThe `--otel-exporter` CLI option was deprecated in 2.1.0 and will be removed. Use environment variable OTEL_EXPORTER_OTLP_ENDPOINT instead.
fix
Replace `--otel-exporter` with `export OTEL_EXPORTER_OTLP_ENDPOINT=<endpoint>`.
affects: >=2.1.0
gotchaThe plugin does not trace subprocess calls by default. If your tests spawn subprocesses, they will not appear in traces.
fix
Manually instrument subprocesses using OpenTelemetry's propagator context extraction.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'opentelemetry'
Missing OpenTelemetry SDK dependency when not using pip extra.
fix
Install the OTLP exporter: `pip install opentelemetry-exporter-otlp`.
TypeError: 'NoneType' object is not callable
Trying to call `pytest_otel.get_tracer()` before plugin initialization.
fix
Do not call the plugin's internal methods. Rely on environment configuration only.
TracerProvider not set, defaulting to noop tracer
No OpenTelemetry tracer provider configured. The plugin issues this warning.
fix
Set the OTEL_TRACES_EXPORTER environment variable to a valid exporter, e.g., `export OTEL_TRACES_EXPORTER=otlp`.
Upgrade
Version history
2.2.1latest on PyPI · released Apr 29, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources

No resource links recorded.