Skip to content

Commit 7d45874

Browse files
test: address Copilot review feedback on test hygiene
- test_migration_processor_extras.py: replace MagicMock() + `del obj.dict` with a small dummy class exposing only `model_dump` so the v2 branch is exercised without depending on Mock's deletion semantics. - test_sk_logic_base.py: capture the original `libs.base.SKBase.SKBaseModel` before patching with our extra-allow stub and restore it in `teardown_module` so the patch no longer leaks across test modules. Both fixes are confined to test files. Coverage remains above the 82% gate (backend 93.28%, processor 87.44%). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5457838 commit 7d45874

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

src/backend-api/src/tests/base/test_sk_logic_base.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,33 @@ class _SKBaseModelStub(BaseModel):
3333
}
3434

3535

36+
# Save whatever was on ``SKBase.SKBaseModel`` before this module ran so we can
37+
# restore it in ``teardown_module`` and avoid leaking our extra-allow stub
38+
# into subsequent test modules. A sentinel distinguishes "attribute was
39+
# missing" from "attribute was None".
40+
_MISSING = object()
41+
_ORIGINAL_SKBASEMODEL = getattr(_skbase_mod, "SKBaseModel", _MISSING)
42+
3643
# Always force-set our stub so it overrides whatever a previously-loaded
3744
# test module installed (e.g. test_kernel_agent.py uses a stricter stub
3845
# without ``extra="allow"`` which prevents SKLogicBase from being constructed).
3946
_skbase_mod.SKBaseModel = _SKBaseModelStub # type: ignore[attr-defined]
4047

48+
49+
def teardown_module(module): # noqa: D401 - pytest hook
50+
"""Restore the original ``SKBaseModel`` attribute on ``libs.base.SKBase``.
51+
52+
This keeps test ordering deterministic: any test module that imports
53+
``SKBaseModel`` after us sees the original value (or absence) rather than
54+
our extra-allow stub. The SUT (``libs.base.SKLogicBase``) is unaffected
55+
because it captured the stub at its own import time.
56+
"""
57+
if _ORIGINAL_SKBASEMODEL is _MISSING:
58+
if hasattr(_skbase_mod, "SKBaseModel"):
59+
delattr(_skbase_mod, "SKBaseModel")
60+
else:
61+
_skbase_mod.SKBaseModel = _ORIGINAL_SKBASEMODEL # type: ignore[attr-defined]
62+
4163
# Ensure libs.base.kernel_agent has been imported (creates real
4264
# semantic_kernel_agent symbol used by the stub below).
4365
import libs.base.kernel_agent as _kernel_agent_mod # noqa: E402

src/processor/src/tests/unit/steps/test_migration_processor_extras.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ def test_details_to_dict_with_dict(self):
3939
assert WorkflowExecutorFailedException._details_to_dict(d) == d
4040

4141
def test_details_to_dict_with_pydantic_v2_object(self):
42-
obj = MagicMock()
43-
obj.model_dump = MagicMock(return_value={"executor_id": "v2"})
44-
del obj.dict # ensure we don't fall through to vars()
45-
result = WorkflowExecutorFailedException._details_to_dict(obj)
42+
class V2Like:
43+
def model_dump(self):
44+
return {"executor_id": "v2"}
45+
46+
result = WorkflowExecutorFailedException._details_to_dict(V2Like())
4647
assert result == {"executor_id": "v2"}
4748

4849
def test_details_to_dict_with_pydantic_v1_object(self):

0 commit comments

Comments
 (0)