From 3ca6b5eda68c2ff55a30018057994fcefa46f61a Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Sun, 28 Jun 2026 05:29:34 +0800 Subject: [PATCH] Scope strategy_registry mock to fixture to avoid pytest collection pollution. Co-authored-by: Cursor --- tests/test_runtime_execution_policy.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/tests/test_runtime_execution_policy.py b/tests/test_runtime_execution_policy.py index 9a175f0..f0b912a 100644 --- a/tests/test_runtime_execution_policy.py +++ b/tests/test_runtime_execution_policy.py @@ -74,11 +74,14 @@ _fake_registry = types.ModuleType("strategy_registry") _fake_registry.PLATFORM_CAPABILITY_MATRIX = _FIRSTRADE_CAPABILITY_MATRIX _fake_registry.STRATEGY_CATALOG = _FAKE_CATALOG -sys.modules["strategy_registry"] = _fake_registry -runtime_execution_policy = importlib.import_module("runtime_execution_policy") -runtime_execution_policy = importlib.reload(runtime_execution_policy) -notional_buy_execution_enabled = runtime_execution_policy.notional_buy_execution_enabled + +@pytest.fixture +def notional_buy_fn(monkeypatch: pytest.MonkeyPatch): + monkeypatch.setitem(sys.modules, "strategy_registry", _fake_registry) + rep = importlib.import_module("runtime_execution_policy") + rep = importlib.reload(rep) + return rep.notional_buy_execution_enabled @pytest.mark.parametrize( @@ -119,7 +122,7 @@ def test_dca_profiles_require_fractional_share_capability() -> None: assert FRACTIONAL_SHARE_EXECUTION_CAPABILITY in definition.compatible_capabilities -def test_firstrade_capability_matrix_allows_dca_profiles() -> None: +def test_firstrade_capability_matrix_allows_dca_profiles(notional_buy_fn) -> None: for profile in ("nasdaq_sp500_smart_dca", "ibit_smart_dca"): assert ( fractional_share_execution_unsupported_reason( @@ -129,9 +132,9 @@ def test_firstrade_capability_matrix_allows_dca_profiles() -> None: ) is None ) - assert notional_buy_execution_enabled(profile) is True + assert notional_buy_fn(profile) is True -def test_notional_buy_execution_disabled_for_non_dca_profiles() -> None: - assert notional_buy_execution_enabled("global_etf_rotation") is False - assert notional_buy_execution_enabled("tqqq_growth_income") is False +def test_notional_buy_execution_disabled_for_non_dca_profiles(notional_buy_fn) -> None: + assert notional_buy_fn("global_etf_rotation") is False + assert notional_buy_fn("tqqq_growth_income") is False