conftest.py 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """Common configuration shared by all tests in this directory."""
  2. import re
  3. from pathlib import Path
  4. import shutil
  5. import pytest
  6. from probs_runner import probs_endpoint
  7. ROOT = Path(__file__).parent.parent
  8. @pytest.fixture(scope="class")
  9. def tmp_path_class(request, tmp_path_factory):
  10. """Like build-in tmp_path fixture but scoped to class."""
  11. name = request.node.name
  12. name = re.sub(r"[\W]", "_", name)
  13. MAXVAL = 30
  14. name = name[:MAXVAL]
  15. return tmp_path_factory.mktemp(name, numbered=True)
  16. @pytest.fixture(scope="class")
  17. def rdfox(request, tmp_path_class):
  18. """Return a function to run a set of datasources"""
  19. working_dir = tmp_path_class
  20. data_paths = [
  21. ROOT / Path(p)
  22. for p in request.cls.endpoint_data
  23. ]
  24. print("Starting endpoint with", data_paths)
  25. with probs_endpoint(
  26. data_paths, working_dir, port=12119
  27. ) as rdfox:
  28. yield rdfox
  29. shutil.rmtree(working_dir)
  30. print("Finished endpoint with", data_paths)