Skip to content

Commit 4cb11a3

Browse files
fix(test): prevent CPA_CATALOG_FIXTURE leak across tests
Clear fixture-related env via os.environ.pop in a shared autouse conftest so monkeypatch teardown cannot restore values set by apply_fixture_mode. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent c6d6ab9 commit 4cb11a3

2 files changed

Lines changed: 39 additions & 20 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""Shared test fixtures for create-awesome-python-app."""
2+
3+
from __future__ import annotations
4+
5+
import os
6+
7+
import pytest
8+
9+
_CPA_ENV_VARS = (
10+
"CPA_REFRESH",
11+
"CPA_NO_CATALOG_CACHE",
12+
"CPA_CACHE_DIR",
13+
"CPA_CATALOG_FIXTURE",
14+
"CPA_FIXTURE_DIR",
15+
)
16+
17+
18+
@pytest.fixture(autouse=True)
19+
def _clean_cpa_process_env() -> None:
20+
"""Clear CPA env vars that CLI helpers set via ``os.environ`` (not monkeypatch).
21+
22+
``apply_fixture_mode`` mutates ``os.environ`` directly. Pairing that with
23+
``monkeypatch.delenv`` after the test can restore the leaked value when
24+
monkeypatch undoes its stack — so cleanup must use ``os.environ.pop``.
25+
"""
26+
from create_awesome_python_app.catalog import (
27+
reset_catalog_cache_for_tests,
28+
reset_fixture_root_for_tests,
29+
)
30+
31+
for name in _CPA_ENV_VARS:
32+
os.environ.pop(name, None)
33+
reset_catalog_cache_for_tests()
34+
reset_fixture_root_for_tests()
35+
yield
36+
for name in _CPA_ENV_VARS:
37+
os.environ.pop(name, None)
38+
reset_catalog_cache_for_tests()
39+
reset_fixture_root_for_tests()

packages/create-awesome-python-app/tests/test_cli.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,6 @@
77
from typer.testing import CliRunner
88

99
runner = CliRunner()
10-
_CPA_ENV_VARS = (
11-
"CPA_REFRESH",
12-
"CPA_NO_CATALOG_CACHE",
13-
"CPA_CACHE_DIR",
14-
"CPA_CATALOG_FIXTURE",
15-
"CPA_FIXTURE_DIR",
16-
)
17-
18-
19-
@pytest.fixture(autouse=True)
20-
def _clean_cpa_env(monkeypatch):
21-
from create_awesome_python_app.catalog import reset_catalog_cache_for_tests
22-
23-
for name in _CPA_ENV_VARS:
24-
monkeypatch.delenv(name, raising=False)
25-
reset_catalog_cache_for_tests()
26-
yield
27-
for name in _CPA_ENV_VARS:
28-
monkeypatch.delenv(name, raising=False)
29-
reset_catalog_cache_for_tests()
3010

3111

3212
def test_version() -> None:

0 commit comments

Comments
 (0)