File tree 2 files changed +35
-11
lines changed
2 files changed +35
-11
lines changed Original file line number Diff line number Diff line change
1
+ from typing import Any , Dict , Optional
2
+
1
3
import pytest
2
4
from _pytest .config import Config
3
5
from _pytest .config .argparsing import Parser
4
6
from _pytest .fixtures import FixtureRequest
5
7
6
8
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
+ }
7
29
8
30
9
31
def pytest_addoption (parser : Parser ) -> None :
Original file line number Diff line number Diff line change 7
7
from tests .conftest import PROXY
8
8
from tests .vcr .vcr_filter import before_record_request , before_record_response
9
9
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
+
10
22
11
23
@pytest .fixture (scope = "session" )
12
24
def vcr_config ():
13
25
# 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
25
27
26
28
27
29
def patch_api_base (requestor ):
You can’t perform that action at this time.
0 commit comments