Skip to content

Commit 255fe10

Browse files
committed
tests: add vcr conf
1 parent d56ca1c commit 255fe10

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scaleway/vcr_config.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import os
2+
from typing import Coroutine, Generator, Any, Optional
3+
4+
import vcr
5+
import inspect
6+
7+
from vcr.cassette import CassetteContextDecorator
8+
9+
PYTHON_UPDATE_CASSETTE = os.getenv("PYTHON_UPDATE_CASSETTE", "false").lower() in ("1", "true", "yes")
10+
11+
class ScwVCR(vcr.VCR):
12+
def use_cassette(self, path: Optional[str] = None, **kwargs):
13+
caller_file = inspect.stack()[1].filename
14+
cassette_dir = os.path.join(os.path.dirname(caller_file), "cassettes")
15+
os.makedirs(cassette_dir, exist_ok=True)
16+
17+
if path is None:
18+
caller_name = os.path.splitext(os.path.basename(caller_file))[0]
19+
path = f"{caller_name}.yaml"
20+
21+
full_path = os.path.join(cassette_dir, path)
22+
return super().use_cassette(full_path, **kwargs)
23+
24+
25+
scw_vcr = ScwVCR(
26+
record_mode="all" if PYTHON_UPDATE_CASSETTE else "none",
27+
filter_headers=["x-auth-token"],
28+
)

0 commit comments

Comments
 (0)