Skip to content

Commit dd10ef2

Browse files
committed
tests: auto path naming cassettes
1 parent e6251c0 commit dd10ef2

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

scaleway/vcr_config.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,20 @@
1+
import logging
12
import os
2-
from typing import Coroutine, Generator, Any, Optional
3+
from typing import Optional
34

45
import vcr
56
import inspect
67

7-
from vcr.cassette import CassetteContextDecorator
8-
98
PYTHON_UPDATE_CASSETTE = os.getenv("PYTHON_UPDATE_CASSETTE", "false").lower() in ("1", "true", "yes")
109

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-
10+
def func_path(function):
11+
path = os.path.join(os.path.dirname(inspect.getfile(function)), "cassettes")
12+
os.makedirs(path, exist_ok=True)
13+
filename = function.__name__ + ".cassette.yaml"
14+
return os.path.join(path, filename)
2415

25-
scw_vcr = ScwVCR(
16+
scw_vcr = vcr.VCR(
2617
record_mode="all" if PYTHON_UPDATE_CASSETTE else "none",
2718
filter_headers=["x-auth-token"],
19+
func_path_generator=func_path
2820
)

0 commit comments

Comments
 (0)