33# pylint: disable=unused-variable
44# pylint: disable=too-many-arguments
55
6+ import json
67from collections .abc import Callable
78from copy import deepcopy
8- from functools import lru_cache
99from pathlib import Path
1010from typing import Any , NamedTuple
1111
@@ -27,23 +27,32 @@ class Entrypoint(NamedTuple):
2727 path : str
2828
2929
30- @lru_cache # ANE: required to boost tests speed, gains 3.5s per test
30+ @pytest .fixture
31+ def openapi_specs_path () -> Path :
32+ # NOTE: cannot be defined as a session scope because it is designed to be overriden
33+ pytest .fail (reason = "Must be overriden in caller test suite" )
34+
35+
3136def _load (file : Path , base_uri : str = "" ) -> dict :
37+ match file .suffix :
38+ case ".yaml" | ".yml" :
39+ loaded = yaml .safe_load (file .read_text ())
40+ case "json" :
41+ loaded = json .loads (file .read_text ())
42+ case _:
43+ msg = f"Expect yaml or json, got { file .suffix } "
44+ raise ValueError (msg )
45+
3246 # SEE https://jsonref.readthedocs.io/en/latest/#lazy-load-and-load-on-repr
3347 data : dict = jsonref .replace_refs ( # type: ignore
34- yaml . safe_load ( file . read_text ()) ,
48+ loaded ,
3549 base_uri = base_uri ,
3650 lazy_load = True , # this data will be iterated
3751 merge_props = False ,
3852 )
3953 return data
4054
4155
42- @pytest .fixture
43- def openapi_specs_path () -> Path :
44- pytest .fail (reason = "Must be overriden in caller tests package" )
45-
46-
4756@pytest .fixture
4857def openapi_specs (openapi_specs_path : Path ) -> dict [str , Any ]:
4958 assert openapi_specs_path .is_file ()
0 commit comments