Skip to content

Commit a492830

Browse files
authored
test: read no contributor dotenv file during pytest (#1271)
1 parent fa9d072 commit a492830

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,13 @@ markers = [
320320
"postgres: require a real PostgreSQL service (SEP_TEST_POSTGRES_DSN)",
321321
"mysql: require a real MySQL service (SEP_TEST_MYSQL_DSN)",
322322
]
323+
# A developer dotenv file must never reach the suite: CI runs with no .env, so
324+
# any setting it carries makes the local run a weaker experiment than CI. This
325+
# pin points PreEnvSettings.ENV_FILE at a committed dotenv file with no
326+
# assignments, so pytest ignores contributor-local dotenv files (exported env
327+
# vars can still override as usual).
323328
env = [
329+
"ENV_FILE=tests/pytest.env",
324330
"AUTH__PROVIDER__CASDOOR__CLIENT_ID=test-client-id",
325331
"AUTH__PROVIDER__CASDOOR__CLIENT_SECRET=test-client-secret",
326332
'AUTH__PROVIDER__CASDOOR__ALLOWED_ISSUERS=["https://allowed-issuer.com"]',

tests/app/sep/apps/alerts/test_api_routes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151

5252
API_BASE = "/api/apps/alerts"
5353
BEARER_HEADERS = {"Authorization": "Bearer test-token"}
54+
#: The parent of every logger the request path emits through. Naming it keeps the
55+
#: "no record carries the secret" assertions from passing on an empty capture.
56+
_APP_LOGGER = "app"
5457

5558

5659
_TEMPLATE_A = AlertTemplate(
@@ -331,7 +334,7 @@ def test_pagerduty_integration_key_with_control_chars_not_echoed(
331334
receiver="default", routes=[]
332335
)
333336
bad_key = "key\x00\nctrl"
334-
with caplog.at_level("DEBUG"):
337+
with caplog.at_level("DEBUG", logger=_APP_LOGGER):
335338
response = api_client.post(
336339
f"{API_BASE}/pagerduty", json={"integration_key": bad_key}
337340
)
@@ -605,7 +608,7 @@ def test_does_not_log_integration_key(self, api_client, mock_pmm_api, caplog):
605608
mock_pmm_api.get_notification_policy.return_value = NotificationPolicy(
606609
receiver="default", routes=[]
607610
)
608-
with caplog.at_level("DEBUG"):
611+
with caplog.at_level("DEBUG", logger=_APP_LOGGER):
609612
response = api_client.post(
610613
f"{API_BASE}/pagerduty",
611614
json={"integration_key": "supersecretkey-xyz"},
@@ -719,7 +722,7 @@ def test_delete_does_not_log_integration_key(
719722
mock_pmm_api.get_notification_policy.return_value = NotificationPolicy(
720723
receiver="default", routes=[]
721724
)
722-
with caplog.at_level("DEBUG"):
725+
with caplog.at_level("DEBUG", logger=_APP_LOGGER):
723726
response = api_client.post(f"{API_BASE}/pagerduty/delete")
724727
assert response.status_code == status.HTTP_200_OK
725728
for record in caplog.records:

tests/app/sep/bundle_upload/test_plan.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
_TICKET_URL = "http://localhost:8000/ticket_details"
4141
_ACCOUNT_URL = "http://localhost:8000/case_account"
4242
_MANIFEST: dict[str, Any] = {"bundle": "diag", "size": 12}
43+
_PLAN_LOGGER = "app.sep.bundle_upload.plan"
4344

4445

4546
@pytest.fixture(name="api")
@@ -695,7 +696,7 @@ async def test_non_json_upload_response_yields_an_empty_result(
695696
body="accepted",
696697
content_type="text/plain",
697698
)
698-
with caplog.at_level("WARNING"):
699+
with caplog.at_level("WARNING", logger=_PLAN_LOGGER):
699700
async with api:
700701
result = await executor.upload_bundle(
701702
source_ref="src-9",
@@ -717,7 +718,7 @@ async def test_list_upload_response_yields_an_empty_result(
717718
mock.post(
718719
_UPLOAD_URL, status=status.HTTP_201_CREATED, payload=[{"sys_id": "x"}]
719720
)
720-
with caplog.at_level("WARNING"):
721+
with caplog.at_level("WARNING", logger=_PLAN_LOGGER):
721722
async with api:
722723
result = await executor.upload_bundle(
723724
source_ref="src-9",
@@ -739,7 +740,7 @@ async def test_unresolvable_reference_pointer_keeps_the_detail(
739740
mock.post(
740741
_UPLOAD_URL, status=status.HTTP_201_CREATED, payload={"other": "x"}
741742
)
742-
with caplog.at_level("WARNING"):
743+
with caplog.at_level("WARNING", logger=_PLAN_LOGGER):
743744
async with api:
744745
result = await executor.upload_bundle(
745746
source_ref="src-9",

tests/pytest.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Contains no dotenv assignments. `[tool.pytest.ini_options] env` points ENV_FILE
2+
# here so a pytest run ignores any developer-local dotenv file, matching CI.
3+
# Settings the suite needs are pinned in that same `env` list; exported env vars
4+
# still override, and per-run values work via `VAR=x pytest ...`.

0 commit comments

Comments
 (0)