Skip to content

Commit f76c673

Browse files
author
Bartek Ogryczak
authored
feat(testing): allow forcing in_test_environment via env var (#68221)
Enables forcing `in_test_environment` to True via `SENTRY_IN_TEST_ENVIRONMENT` env var. This allows invoking pytest via other scripts directly from Python code via `pytest.main(...)`
1 parent a4d19ab commit f76c673

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/sentry/utils/env.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@
99

1010

1111
def in_test_environment() -> bool:
12-
return "pytest" in sys.argv[0] or "vscode" in sys.argv[0]
12+
return (
13+
"pytest" in sys.argv[0]
14+
or "vscode" in sys.argv[0]
15+
or os.environ.get("SENTRY_IN_TEST_ENVIRONMENT") in {"1", "true"}
16+
)
1317

1418

1519
def gcp_project_id() -> str:

0 commit comments

Comments
 (0)