util.py 649 B

1234567891011121314151617
  1. import os.path
  2. from pathlib import Path
  3. import importlib.util
  4. def import_and_execute_test_script(relative_path_to_test_script: str):
  5. """Imports and executes a module from a path relative to Ray repo root."""
  6. # get the ray folder
  7. ray_path = Path(
  8. os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..", ".."))
  9. )
  10. notebook_path = ray_path.joinpath(relative_path_to_test_script)
  11. assert notebook_path.exists()
  12. spec = importlib.util.spec_from_file_location("notebook_test", notebook_path)
  13. notebook_test_module = importlib.util.module_from_spec(spec)
  14. spec.loader.exec_module(notebook_test_module)