No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

38 líneas
1.2KB

  1. from contextlib import ExitStack
  2. from typing import Optional
  3. from pathlib import Path
  4. import shutil
  5. import pytest
  6. from tests import scoped_dds, DDSFixtureParams
  7. @pytest.yield_fixture
  8. def dds(request, tmp_path: Path, worker_id: str, scope: ExitStack):
  9. test_source_dir = Path(request.fspath).absolute().parent
  10. test_root = test_source_dir
  11. # If we are running in parallel, use a unique directory as scratch
  12. # space so that we aren't stomping on anyone else
  13. if worker_id != 'master':
  14. test_root = tmp_path / request.function.__name__
  15. shutil.copytree(test_source_dir, test_root)
  16. project_dir = test_root / 'project'
  17. # Check if we have a special configuration
  18. if hasattr(request, 'param'):
  19. assert isinstance(request.param, DDSFixtureParams), \
  20. ('Using the `dds` fixture requires passing in indirect '
  21. 'params. Use @dds_fixture_conf to configure the fixture')
  22. params: DDSFixtureParams = request.param
  23. project_dir = test_root / params.subdir
  24. # Create the instance. Auto-clean when we're done
  25. yield scope.enter_context(scoped_dds(test_root, project_dir, request.function.__name__))
  26. @pytest.fixture
  27. def scope():
  28. with ExitStack() as scope:
  29. yield scope