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.

77 lines
2.6KB

  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(pytestconfig) -> Path:
  11. return Path(pytestconfig.getoption('--dds-exe'))
  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('--test-deps',
  43. action='store_true',
  44. default=False,
  45. help='Run the exhaustive and intensive dds-deps tests')
  46. parser.addoption('--dds-exe', help='Path to the dds executable under test', required=True, type=Path)
  47. def pytest_configure(config):
  48. config.addinivalue_line('markers', 'deps_test: Deps tests are slow. Enable with --test-deps')
  49. def pytest_collection_modifyitems(config, items):
  50. if config.getoption('--test-deps'):
  51. return
  52. for item in items:
  53. if 'deps_test' not in item.keywords:
  54. continue
  55. item.add_marker(
  56. pytest.mark.skip(
  57. reason='Exhaustive deps tests are slow and perform many Git clones. Use --test-deps to run them.'))