Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

74 lines
2.4KB

  1. from contextlib import ExitStack
  2. from typing import Optional
  3. from pathlib import Path
  4. import shutil
  5. from subprocess import check_call
  6. import pytest
  7. from tests import scoped_dds, DDSFixtureParams
  8. from .http import * # Exposes the HTTP fixtures
  9. @pytest.fixture(scope='session')
  10. def dds_exe() -> Path:
  11. return Path(__file__).absolute().parent.parent / '_build/dds'
  12. @pytest.yield_fixture(scope='session')
  13. def dds_pizza_catalog(dds_exe: Path, tmp_path_factory) -> Path:
  14. tmpdir: Path = tmp_path_factory.mktemp(basename='dds-catalog')
  15. cat_path = tmpdir / 'catalog.db'
  16. check_call([str(dds_exe), 'repo', 'add', 'https://dds.pizza/repo', '--update', f'--catalog={cat_path}'])
  17. yield cat_path
  18. @pytest.yield_fixture
  19. def dds(request, dds_exe: Path, tmp_path: Path, worker_id: str, scope: ExitStack):
  20. test_source_dir = Path(request.fspath).absolute().parent
  21. test_root = test_source_dir
  22. # If we are running in parallel, use a unique directory as scratch
  23. # space so that we aren't stomping on anyone else
  24. if worker_id != 'master':
  25. test_root = tmp_path / request.function.__name__
  26. shutil.copytree(test_source_dir, test_root)
  27. project_dir = test_root / 'project'
  28. # Check if we have a special configuration
  29. if hasattr(request, 'param'):
  30. assert isinstance(request.param, DDSFixtureParams), \
  31. ('Using the `dds` fixture requires passing in indirect '
  32. 'params. Use @dds_fixture_conf to configure the fixture')
  33. params: DDSFixtureParams = request.param
  34. project_dir = test_root / params.subdir
  35. # Create the instance. Auto-clean when we're done
  36. yield scope.enter_context(scoped_dds(dds_exe, test_root, project_dir, request.function.__name__))
  37. @pytest.fixture
  38. def scope():
  39. with ExitStack() as scope:
  40. yield scope
  41. def pytest_addoption(parser):
  42. parser.addoption(
  43. '--test-deps', action='store_true', default=False, help='Run the exhaustive and intensive dds-deps tests')
  44. def pytest_configure(config):
  45. config.addinivalue_line('markers', 'deps_test: Deps tests are slow. Enable with --test-deps')
  46. def pytest_collection_modifyitems(config, items):
  47. if config.getoption('--test-deps'):
  48. return
  49. for item in items:
  50. if 'deps_test' not in item.keywords:
  51. continue
  52. item.add_marker(
  53. pytest.mark.skip(
  54. reason='Exhaustive deps tests are slow and perform many Git clones. Use --test-deps to run them.'))