loader.py 864 B

123456789101112131415161718192021
  1. import pytest
  2. from .lazy_fixture import LazyFixtureWrapper
  3. from .lazy_fixture_callable import LazyFixtureCallableWrapper
  4. def load_lazy_fixtures(value, request: pytest.FixtureRequest):
  5. if isinstance(value, LazyFixtureCallableWrapper):
  6. return value.get_func(request)(
  7. *load_lazy_fixtures(value.args, request),
  8. **load_lazy_fixtures(value.kwargs, request),
  9. )
  10. if isinstance(value, LazyFixtureWrapper):
  11. return value.load_fixture(request)
  12. # we need to check exact type
  13. if type(value) is dict: # noqa: E721
  14. return {load_lazy_fixtures(key, request): load_lazy_fixtures(value, request) for key, value in value.items()}
  15. # we need to check exact type
  16. elif type(value) in {list, tuple, set}:
  17. return type(value)([load_lazy_fixtures(value, request) for value in value])
  18. return value