Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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