You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 line
2.0KB

  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(
  26. scoped_dds(test_root, project_dir, request.function.__name__))
  27. @pytest.fixture
  28. def scope():
  29. with ExitStack() as scope:
  30. yield scope
  31. def pytest_addoption(parser):
  32. parser.addoption(
  33. '--test-deps',
  34. action='store_true',
  35. default=False,
  36. help='Run the exhaustive and intensive dds-deps tests')
  37. def pytest_configure(config):
  38. config.addinivalue_line(
  39. 'markers', 'deps_test: Deps tests are slow. Enable with --test-deps')
  40. def pytest_collection_modifyitems(config, items):
  41. if config.getoption('--test-deps'):
  42. return
  43. for item in items:
  44. if 'deps_test' not in item.keywords:
  45. continue
  46. item.add_marker(
  47. pytest.mark.skip(
  48. reason=
  49. 'Exhaustive deps tests are slow and perform many Git clones. Use --test-deps to run them.'
  50. ))