Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test generation #775

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion metagpt/actions/run_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
class.
"""
import subprocess
from pathlib import Path
from typing import Tuple

from pydantic import Field
Expand Down Expand Up @@ -152,11 +153,23 @@ def _install_via_subprocess(cmd, check, cwd, env):
return subprocess.run(cmd, check=check, cwd=cwd, env=env)

@staticmethod
def _install_dependencies(working_directory, env):
def _install_requirements(working_directory, env):
file_path = Path(working_directory) / "requirements.txt"
if not file_path.exists():
return
if file_path.stat().st_size == 0:
return
install_command = ["python", "-m", "pip", "install", "-r", "requirements.txt"]
logger.info(" ".join(install_command))
RunCode._install_via_subprocess(install_command, check=True, cwd=working_directory, env=env)

@staticmethod
def _install_pytest(working_directory, env):
install_pytest_command = ["python", "-m", "pip", "install", "pytest"]
logger.info(" ".join(install_pytest_command))
RunCode._install_via_subprocess(install_pytest_command, check=True, cwd=working_directory, env=env)

@staticmethod
def _install_dependencies(working_directory, env):
RunCode._install_requirements(working_directory, env)
RunCode._install_pytest(working_directory, env)
2 changes: 2 additions & 0 deletions metagpt/roles/qa_engineer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ async def _write_test(self, message: Message) -> None:
code_doc = await src_file_repo.get(filename)
if not code_doc:
continue
if not code_doc.filename.endswith(".py"):
continue
test_doc = await tests_file_repo.get("test_" + code_doc.filename)
if not test_doc:
test_doc = Document(
Expand Down
Loading