Skip to content

Commit e7fea50

Browse files
committed
Fix Significant-Gravitas#4461: Don't record error requests in challenges
1 parent 1446ffd commit e7fea50

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

tests/integration/challenges/conftest.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,31 @@
1+
from typing import Any, Dict, Optional
2+
13
import pytest
24
from _pytest.config import Config
35
from _pytest.config.argparsing import Parser
46
from _pytest.fixtures import FixtureRequest
57

68
from tests.integration.challenges.challenge_decorator.challenge import Challenge
9+
from tests.integration.conftest import BASE_VCR_CONFIG
10+
from tests.vcr.vcr_filter import before_record_response
11+
12+
13+
def before_record_response_filter_errors(
14+
response: Dict[str, Any]
15+
) -> Optional[Dict[str, Any]]:
16+
"""In challenges we don't want to record errors (See issue #4461)"""
17+
if response["status"]["code"] >= 400:
18+
return None
19+
20+
return before_record_response(response)
21+
22+
23+
@pytest.fixture(scope="module")
24+
def vcr_config() -> Dict[str, Any]:
25+
# this fixture is called by the pytest-recording vcr decorator.
26+
return BASE_VCR_CONFIG | {
27+
"before_record_response": before_record_response_filter_errors,
28+
}
729

830

931
def pytest_addoption(parser: Parser) -> None:

tests/integration/conftest.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,23 @@
77
from tests.conftest import PROXY
88
from tests.vcr.vcr_filter import before_record_request, before_record_response
99

10+
BASE_VCR_CONFIG = {
11+
"record_mode": "new_episodes",
12+
"before_record_request": before_record_request,
13+
"before_record_response": before_record_response,
14+
"filter_headers": [
15+
"Authorization",
16+
"X-OpenAI-Client-User-Agent",
17+
"User-Agent",
18+
],
19+
"match_on": ["method", "body"],
20+
}
21+
1022

1123
@pytest.fixture(scope="session")
1224
def vcr_config():
1325
# this fixture is called by the pytest-recording vcr decorator.
14-
return {
15-
"record_mode": "new_episodes",
16-
"before_record_request": before_record_request,
17-
"before_record_response": before_record_response,
18-
"filter_headers": [
19-
"Authorization",
20-
"X-OpenAI-Client-User-Agent",
21-
"User-Agent",
22-
],
23-
"match_on": ["method", "body"],
24-
}
26+
return BASE_VCR_CONFIG
2527

2628

2729
def patch_api_base(requestor):

0 commit comments

Comments
 (0)