🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
refine tests
geekanf182b290cce4
diff --git a/metagpt/actions/run_code.py b/metagpt/actions/run_code.pyindex 22d345b85..d22aa47ce 100644--- a/metagpt/actions/run_code.py+++ b/metagpt/actions/run_code.py@@ -82,11 +82,13 @@ class RunCode(Action):llm: BaseLLM = Field(default_factory=LLM)@classmethod- @handle_exceptionasync def run_text(cls, code) -> Tuple[str, str]:- # We will document_store the result in this dictionary- namespace = {}- exec(code, namespace)+ try:+ # We will document_store the result in this dictionary+ namespace = {}+ exec(code, namespace)+ except Exception as e:+ return "", str(e)return namespace.get("result", ""), ""@classmethoddiff --git a/tests/metagpt/actions/test_run_code.py b/tests/metagpt/actions/test_run_code.pyindex 888418974..ad08b5738 100644--- a/tests/metagpt/actions/test_run_code.py+++ b/tests/metagpt/actions/test_run_code.py@@ -14,13 +14,13 @@ from metagpt.schema import RunCodeContext@pytest.mark.asyncioasync def test_run_text():- result, errs = await RunCode.run_text("result = 1 + 1")- assert result == 2- assert errs == ""+ out, err = await RunCode.run_text("result = 1 + 1")+ assert out == 2+ assert err == ""- result, errs = await RunCode.run_text("result = 1 / 0")- assert result == ""- assert "ZeroDivisionError" in errs+ out, err = await RunCode.run_text("result = 1 / 0")+ assert out == ""+ assert "division by zero" in err@pytest.mark.asynciodiff --git a/tests/metagpt/test_role.py b/tests/metagpt/test_role.pyindex dbe45130d..2903913bb 100644--- a/tests/metagpt/test_role.py+++ b/tests/metagpt/test_role.py@@ -63,9 +63,9 @@ async def test_react():assert role._rc.watch == {any_to_str(UserRequirement)}assert role.name == seed.nameassert role.profile == seed.profile- assert role._setting.goal == seed.goal- assert role._setting.constraints == seed.constraints- assert role._setting.desc == seed.desc+ assert role.goal == seed.goal+ assert role.constraints == seed.constraints+ assert role.desc == seed.descassert role.is_idleenv = Environment()env.add_role(role)diff --git a/tests/metagpt/test_team.py b/tests/metagpt/test_team.pyindex 930306b5e..a97fc78bf 100644--- a/tests/metagpt/test_team.py+++ b/tests/metagpt/test_team.py@@ -10,4 +10,4 @@ def test_team():company = Team()company.hire([ProjectManager()])- assert len(company.environment.roles) == 1+ assert len(company.env.roles) == 1