Skip to content

Commit 5d6cf7e

Browse files
sl0thentr0pyclaude
andauthored
ref(tox): Allow overriding TESTPATH via env var for targeted test runs (#5699)
### Description Allows better agentic testing flow. Rename internal `TESTPATH` to `_TESTPATH` in setenv and add `TESTPATH` to `passenv`. The pytest command now uses `{env:TESTPATH:{env:_TESTPATH}}`, so setting TESTPATH externally overrides the default test path. This allows running specific test files without the --override workaround: ``` TESTPATH=tests/integrations/logging/test_logging.py tox -e py3.14-common ``` Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 238cadf commit 5d6cf7e

File tree

7 files changed

+154
-137
lines changed

7 files changed

+154
-137
lines changed

.claude/settings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@
2727
"WebFetch(domain:docs.sentry.io)",
2828
"WebFetch(domain:develop.sentry.dev)",
2929
"Bash(grep:*)",
30-
"Bash(mv:*)"
30+
"Bash(mv:*)",
31+
"Bash(source .venv/bin/activate)",
32+
"Bash(tox:*)",
33+
"Bash(tox.venv/bin/tox:*)",
34+
"Bash(.tox/*/bin/python:*)",
35+
"Bash(.tox/*/bin/pytest:*)",
36+
"Bash(.tox/*/bin/ruff:*)"
3137
],
3238
"deny": []
3339
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ sentry-python-serverless*.zip
2222
venv
2323
.venv
2424
tox.venv
25+
toxgen.venv
2526
.vscode/tags
2627
.pytest_cache
2728
.hypothesis

AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Use **tox** for testing (not pytest directly):
1111
- Test matrix configuration is in `tox.ini`
1212
- Integration tests: `tox -e py3.14-{integration}-v{version}`
1313
- Common tests: `tox -e py3.14-common`
14+
- Run specific test file: `TESTPATH=tests/integrations/logging/test_logging.py tox -e py3.14-common`
15+
- Run single test: `TESTPATH=tests/path/to/test_file.py tox -e py3.14-common -- -k "test_name"`
1416

1517
## Type Checking
1618

scripts/populate_tox/package_dependencies.jsonl

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

scripts/populate_tox/releases.jsonl

Lines changed: 19 additions & 17 deletions
Large diffs are not rendered by default.

scripts/populate_tox/tox.jinja

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,30 @@ setenv =
168168
gevent: PYTEST_ADDOPTS="--ignore=tests/test_shadowed_module.py"
169169
170170
# TESTPATH definitions for test suites not managed by toxgen
171-
common: TESTPATH=tests
172-
gevent: TESTPATH=tests
173-
integration_deactivation: TESTPATH=tests/test_ai_integration_deactivation.py
174-
shadowed_module: TESTPATH=tests/test_shadowed_module.py
175-
asgi: TESTPATH=tests/integrations/asgi
176-
aws_lambda: TESTPATH=tests/integrations/aws_lambda
177-
cloud_resource_context: TESTPATH=tests/integrations/cloud_resource_context
178-
gcp: TESTPATH=tests/integrations/gcp
179-
opentelemetry: TESTPATH=tests/integrations/opentelemetry
180-
otlp: TESTPATH=tests/integrations/otlp
181-
potel: TESTPATH=tests/integrations/opentelemetry
182-
socket: TESTPATH=tests/integrations/socket
171+
common: _TESTPATH=tests
172+
gevent: _TESTPATH=tests
173+
integration_deactivation: _TESTPATH=tests/test_ai_integration_deactivation.py
174+
shadowed_module: _TESTPATH=tests/test_shadowed_module.py
175+
asgi: _TESTPATH=tests/integrations/asgi
176+
aws_lambda: _TESTPATH=tests/integrations/aws_lambda
177+
cloud_resource_context: _TESTPATH=tests/integrations/cloud_resource_context
178+
gcp: _TESTPATH=tests/integrations/gcp
179+
opentelemetry: _TESTPATH=tests/integrations/opentelemetry
180+
otlp: _TESTPATH=tests/integrations/otlp
181+
potel: _TESTPATH=tests/integrations/opentelemetry
182+
socket: _TESTPATH=tests/integrations/socket
183183
184184
# These TESTPATH definitions are auto-generated by toxgen
185185
{% for integration, testpath in testpaths %}
186-
{{ integration }}: TESTPATH={{ testpath }}
186+
{{ integration }}: _TESTPATH={{ testpath }}
187187
{% endfor %}
188188
189189
passenv =
190190
SENTRY_PYTHON_TEST_POSTGRES_HOST
191191
SENTRY_PYTHON_TEST_POSTGRES_USER
192192
SENTRY_PYTHON_TEST_POSTGRES_PASSWORD
193193
SENTRY_PYTHON_TEST_POSTGRES_NAME
194+
TESTPATH
194195
195196
usedevelop = True
196197
@@ -228,7 +229,7 @@ commands =
228229
; Running `pytest` as an executable suffers from an import error
229230
; when loading tests in scenarios. In particular, django fails to
230231
; load the settings from the test module.
231-
python -m pytest -W error::pytest.PytestUnraisableExceptionWarning {env:TESTPATH} -o junit_suite_name={envname} {posargs}
232+
python -m pytest -W error::pytest.PytestUnraisableExceptionWarning {env:TESTPATH:{env:_TESTPATH}} -o junit_suite_name={envname} {posargs}
232233
233234
[testenv:linters]
234235
commands =

0 commit comments

Comments
 (0)