AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
Fix #4461: Don't record error requests in challenges (#4469)
Erik Petersonb56352e2183d
diff --git a/tests/integration/challenges/conftest.py b/tests/integration/challenges/conftest.pyindex 8a1b5c406b..5514a1293f 100644--- a/tests/integration/challenges/conftest.py+++ b/tests/integration/challenges/conftest.py@@ -1,9 +1,31 @@+from typing import Any, Dict, Optional+import pytestfrom _pytest.config import Configfrom _pytest.config.argparsing import Parserfrom _pytest.fixtures import FixtureRequestfrom tests.integration.challenges.challenge_decorator.challenge import Challenge+from tests.integration.conftest import BASE_VCR_CONFIG+from tests.vcr.vcr_filter import before_record_response+++def before_record_response_filter_errors(+ response: Dict[str, Any]+) -> Optional[Dict[str, Any]]:+ """In challenges we don't want to record errors (See issue #4461)"""+ if response["status"]["code"] >= 400:+ return None++ return before_record_response(response)++[email protected](scope="module")+def vcr_config() -> Dict[str, Any]:+ # this fixture is called by the pytest-recording vcr decorator.+ return BASE_VCR_CONFIG | {+ "before_record_response": before_record_response_filter_errors,+ }def pytest_addoption(parser: Parser) -> None:diff --git a/tests/integration/conftest.py b/tests/integration/conftest.pyindex cb49bc13a6..686f50be40 100644--- a/tests/integration/conftest.py+++ b/tests/integration/conftest.py@@ -7,21 +7,23 @@ from pytest_mock import MockerFixturefrom tests.conftest import PROXYfrom tests.vcr.vcr_filter import before_record_request, before_record_response+BASE_VCR_CONFIG = {+ "record_mode": "new_episodes",+ "before_record_request": before_record_request,+ "before_record_response": before_record_response,+ "filter_headers": [+ "Authorization",+ "X-OpenAI-Client-User-Agent",+ "User-Agent",+ ],+ "match_on": ["method", "body"],+}+@pytest.fixture(scope="session")def vcr_config():# this fixture is called by the pytest-recording vcr decorator.- return {- "record_mode": "new_episodes",- "before_record_request": before_record_request,- "before_record_response": before_record_response,- "filter_headers": [- "Authorization",- "X-OpenAI-Client-User-Agent",- "User-Agent",- ],- "match_on": ["method", "body"],- }+ return BASE_VCR_CONFIGdef patch_api_base(requestor):