Selfie
Loading...
Searching...
No Matches
SelfieSettingsAPI.py
Go to the documentation of this file.
1import os
2from pathlib import Path
3from typing import Optional
4
5import pytest
6from selfie_lib import Mode
7
8
10 """API for configuring the selfie plugin, you can set its values like this https://docs.pytest.org/en/7.1.x/reference/customize.html#configuration-file-formats"""
11
12 def __init__(self, config: pytest.Config):
13 self.root_dir = config.rootpath
14
15 @property
17 """Allow multiple equivalent writes to one location."""
18 return True
19
20 @property
21 def snapshot_folder_name(self) -> Optional[str]:
22 """Defaults to None, which means that snapshots are stored right next to the test that created them."""
23 return None
24
25 @property
26 def root_folder(self) -> Path:
27 """Returns the root folder for storing snapshots. Set by https://docs.pytest.org/en/7.1.x/reference/customize.html#finding-the-rootdir"""
28 return self.root_dir
29
30 def calc_mode(self) -> Mode:
31 override = os.getenv("selfie") or os.getenv("SELFIE") # noqa: SIM112
32 if override:
33 # Convert the mode to lowercase and match it with the Mode enum
34 try:
35 return Mode[override.lower()]
36 except KeyError:
37 raise ValueError(f"No such mode: {override}") from None
38
39 ci = os.getenv("ci") or os.getenv("CI") # noqa: SIM112
40 if ci and ci.lower() == "true":
41 return Mode.readonly
42 else:
43 return Mode.interactive
44
45
46class SelfieSettingsSmuggleError(SelfieSettingsAPI):
47 def __init__(self, error: BaseException):
48 self.error = error