File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 2626
2727if TYPE_CHECKING :
2828 import pytest
29+ from requests import PreparedRequest
2930
3031log = logging .getLogger (__name__ )
3132
@@ -323,7 +324,25 @@ def session_with_stored_responses(pytestconfig):
323324 3. is treated with :func:`.offline`, so that *only* stored responses can be
324325 returned.
325326 """
326- session = Session (backend = "memory" )
327+ from requests_cache import create_key
328+
329+ def _key_fn (request : "PreparedRequest" , ** kwargs ) -> str :
330+ """Match existing stored responses with different `Accept-Encoding` headers.
331+
332+ Stored responses in sdmx-test-data have "Accept-Encoding: gzip, deflate"; with
333+ Python 3.14, the prepared request has "gzip, deflate, zstd`. Simplify so the
334+ existing keys match.
335+ """
336+ exp = "gzip, deflate"
337+ if exp in request .headers .get ("Accept-Encoding" , "" ):
338+ # Don't modify the original request that's about to be sent
339+ request = request .copy ()
340+ request .headers ["Accept-Encoding" ] = exp
341+
342+ # Use the default key function to do the rest of the work
343+ return create_key (request , ** kwargs )
344+
345+ session = Session (backend = "memory" , key_fn = _key_fn )
327346
328347 data .add_responses (
329348 session ,
You can’t perform that action at this time.
0 commit comments