diff --git a/.github/workflows/unittest.yaml b/.github/workflows/unittest.yaml index 4255f7797..a3321aa7d 100644 --- a/.github/workflows/unittest.yaml +++ b/.github/workflows/unittest.yaml @@ -23,7 +23,7 @@ jobs: - name: Test with pytest run: | echo "${{ secrets.METAGPT_KEY_YAML }}" | base64 -d > config/key.yaml - pytest tests/ --doctest-modules --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=./metagpt/ --cov-report=xml:cov.xml --cov-report=html:htmlcov --durations=20 + pytest tests/ --doctest-modules --cov=./metagpt/ --cov-report=xml:cov.xml --cov-report=html:htmlcov --durations=20 | tee unittest.txt - name: Show coverage report run: | coverage report -m @@ -32,7 +32,7 @@ jobs: with: name: pytest-results-${{ matrix.python-version }} path: | - ./junit/test-results-${{ matrix.python-version }}.xml + ./unittest.txt ./htmlcov/ ./tests/data/rsp_cache_new.json retention-days: 3 diff --git a/.gitignore b/.gitignore index 2c59f3b59..240966a48 100644 --- a/.gitignore +++ b/.gitignore @@ -52,6 +52,7 @@ coverage.xml .hypothesis/ .pytest_cache/ cover/ +unittest.txt # Translations *.mo diff --git a/metagpt/tools/search_engine_serpapi.py b/metagpt/tools/search_engine_serpapi.py index 4fd2b94b8..9d2d20af6 100644 --- a/metagpt/tools/search_engine_serpapi.py +++ b/metagpt/tools/search_engine_serpapi.py @@ -18,7 +18,7 @@ class SerpAPIWrapper(BaseModel): search_engine: Any = None #: :meta private: params: dict = Field( - default={ + default_factory=lambda: { "engine": "google", "google_domain": "google.com", "gl": "us", diff --git a/metagpt/tools/search_engine_serper.py b/metagpt/tools/search_engine_serper.py index 3707d905d..3dc1d3591 100644 --- a/metagpt/tools/search_engine_serper.py +++ b/metagpt/tools/search_engine_serper.py @@ -9,14 +9,16 @@ import json from typing import Any, Dict, Optional, Tuple import aiohttp -from pydantic import BaseModel, Field, field_validator +from pydantic import BaseModel, ConfigDict, Field, field_validator from metagpt.config import CONFIG class SerperWrapper(BaseModel): + model_config = ConfigDict(arbitrary_types_allowed=True) + search_engine: Any = None #: :meta private: - payload: dict = Field(default={"page": 1, "num": 10}) + payload: dict = Field(default_factory=lambda: {"page": 1, "num": 10}) serper_api_key: Optional[str] = Field(default=None, validate_default=True) aiosession: Optional[aiohttp.ClientSession] = None diff --git a/tests/metagpt/tools/test_search_engine.py b/tests/metagpt/tools/test_search_engine.py index 47b50337f..dcf1eec69 100644 --- a/tests/metagpt/tools/test_search_engine.py +++ b/tests/metagpt/tools/test_search_engine.py @@ -58,7 +58,7 @@ async def test_search_engine(search_engine_type, run_func: Callable, max_results assert isinstance(rsp, str) else: assert isinstance(rsp, list) - assert len(rsp) == max_results + assert len(rsp) <= max_results if __name__ == "__main__":