Skip to content

Commit cba537e

Browse files
CopilotCopilot
authored andcommitted
fix: add setup_module to prevent test ordering issues with Message patch
The teardown_module from one test file was restoring the real Message before another test file's tests ran. Adding setup_module ensures the stub is re-applied before each module's tests execute. Also fix test assertion to check contents instead of text since the middleware now uses Message(contents=). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d60d5b1 commit cba537e

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

src/processor/src/tests/unit/libs/agent_framework/test_groupchat_orchestrator_internals.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ def __init__(self, *, role, text=None, contents=None, author_name=None):
4040
)
4141

4242

43+
def setup_module(module=None):
44+
"""Re-apply the Message patch in case another module's teardown restored it."""
45+
groupchat_module.Message = Message
46+
47+
4348
def teardown_module(module=None):
4449
"""Restore the original Message class to avoid leaking into other tests."""
4550
if _original_message is not None:

src/processor/src/tests/unit/libs/agent_framework/test_input_observer_middleware.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ def __init__(self, *, role, text=None, contents=None, author_name=None):
2626
from libs.agent_framework.middlewares import InputObserverMiddleware # noqa: E402
2727

2828

29+
def setup_module(module=None):
30+
"""Re-apply the Message patch in case another module's teardown restored it."""
31+
middlewares_module.Message = Message
32+
33+
2934
def teardown_module(module=None):
3035
"""Restore the original Message class to avoid leaking into other tests."""
3136
if _original_message is not None:

src/processor/src/tests/unit/libs/agent_framework/test_middlewares_extras.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ def __init__(self, *, role, text=None, contents=None, author_name=None):
3333
)
3434

3535

36+
def setup_module(module=None):
37+
"""Re-apply the Message patch in case another module's teardown restored it."""
38+
middlewares_module.Message = Message
39+
40+
3641
def teardown_module(module=None):
3742
"""Restore the original Message class to avoid leaking into other tests."""
3843
if _original_message is not None:
@@ -130,4 +135,4 @@ def test_no_replacement_keeps_text(self):
130135
ctx.messages = [msg]
131136
mw = InputObserverMiddleware(replacement=None)
132137
_run(mw.process(ctx, AsyncMock()))
133-
assert ctx.messages[0].text == "keep me"
138+
assert ctx.messages[0].contents == "keep me"

0 commit comments

Comments
 (0)