Skip to content

feat(python): add Python/pytest support#91

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
gnufede/pytest-support-0
Jun 22, 2026
Merged

feat(python): add Python/pytest support#91
gh-worker-dd-mergequeue-cf854d[bot] merged 1 commit into
mainfrom
gnufede/pytest-support-0

Conversation

@gnufede

@gnufede gnufede commented Jun 19, 2026

Copy link
Copy Markdown
Member

What

Adds Python/pytest support to ddtest, making it possible to use Test Impact Analysis and test skipping for Python projects using pytest.

New platform (python) and framework (pytest) that integrate with the existing ddtest architecture:

  • Platform detection: reads runtime tags (runtime.name, runtime.version, os.platform, etc.) from the Python interpreter via an embedded script, and verifies that ddtrace >= 4.10.3 is installed
  • Test discovery: resolves pytest config (pytest.ini, pyproject.toml, tox.ini, setup.cfg) to find testpaths and python_files, builds a glob pattern, and passes explicit file paths to python -m pytest (pytest has no --pattern flag like RSpec does)
  • Test running: injects --ddtrace into PYTEST_ADDOPTS so the ddtrace pytest plugin loads automatically without requiring changes to the project's pytest config
  • Manifest: sets both TEST_OPTIMIZATION_MANIFEST_FILE and DD_TEST_OPTIMIZATION_MANIFEST_FILE in worker env — dd-trace-py reads the latter

Why

Python/pytest is one of the most widely used test stacks. Supporting it in ddtest allows Python teams to benefit from Test Impact Analysis (skipping tests unaffected by a code change), reducing CI time.

E2E testing

Requirements: Python with ddtrace >= 4.10.3 and pytest installed, a Datadog API key with Test Optimization enabled.

Create a small fixture project:

mkdir -p /tmp/pytest-fixture/tests && cd /tmp/pytest-fixture
git init

cat > tests/test_math.py <<'PY'
def test_add(): assert 1 + 1 == 2
def test_subtract(): assert 5 - 3 == 2
PY

cat > pytest.ini <<'INI'
[pytest]
testpaths = tests
INI

git add . && git commit -m "initial fixture"

Run plan then run:

export DD_API_KEY=<your-key>
export DD_CIVISIBILITY_AGENTLESS_ENABLED=true
export DD_ENV=<your-env>
export DD_SERVICE=<your-service>
export DD_TEST_OPTIMIZATION_RUNNER_PLATFORM=python
export DD_TEST_OPTIMIZATION_RUNNER_FRAMEWORK=pytest

ddtest plan   # discovers tests, fetches skippable list from Datadog
ddtest run    # runs pytest in parallel workers with --ddtrace injected

Expected plan output includes Platform: python / pytest, correct runtime tags (CPython, runtime.version), and discovered tests listed per file. After a few runs with coverage data collected, an unrelated commit (e.g. editing a README) should show Skippable tests for this run: N with the full test suites skipped.

@gnufede gnufede changed the title feat(python): add Python/pytest support compatible with PRs 77/81/84/… feat(python): add Python/pytest support Jun 19, 2026
@gnufede gnufede force-pushed the gnufede/pytest-support-0 branch from c322d50 to 49156a1 Compare June 22, 2026 09:53
@gnufede gnufede mentioned this pull request Jun 22, 2026
…87/88/89

Adapt the Python platform and pytest framework implementation to the updated
codebase structure introduced by the recent merged PRs:

- Implement the new Framework interface: TestPattern() replaces DiscoverTestFiles(),
  and DiscoverTests() now accepts discovery.TestFileSet from the planner
- pytest resolves glob patterns to explicit files (python has no --pattern flag)
- Move discovery helpers to the discovery package (Cleanup, DiscoverTests, BaseEnv)
- Add DDTestOptimizationManifestFileEnvVar support for dd-trace-py manifest lookup
- Add PythonEnvOutputPath constant and DDTEST_LOG_LEVEL debug support in main.go
- Update worker_env.go to set both manifest env vars for Python workers

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@gnufede gnufede force-pushed the gnufede/pytest-support-0 branch from 49156a1 to 7031c71 Compare June 22, 2026 11:12
@gnufede gnufede marked this pull request as ready for review June 22, 2026 11:12
@gnufede gnufede requested a review from a team as a code owner June 22, 2026 11:12
@datadog-official

Copy link
Copy Markdown

Tests  Code Coverage

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 79.44%
Overall Coverage: 87.13% (-0.36%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 7031c71 | Docs | Datadog PR Page | Give us feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants