add test_runner_runner_dict_import_failing

This commit is contained in:
Daniel 2023-12-15 14:42:45 +01:00
parent b2c9862589
commit d4b6ade31a
2 changed files with 29 additions and 1 deletions

View file

@ -1,5 +1,6 @@
import os
import shutil
import sys
from pathlib import Path
import pytest
@ -41,3 +42,25 @@ def test_runner_runner_dict_import(tmp_recipes: Path):
RUNNER_DICT = Coordinator.create_runner_dict(tmp_recipes)
assert len(RUNNER_DICT.keys()) > 0
@pytest.fixture
def clear_sys_path():
"""clear sys.path before test, restore after"""
syspath_copy = sys.path.copy()
sys.path.clear()
yield
sys.path.extend(syspath_copy)
def test_runner_runner_dict_import_failing(tmp_recipes: Path, clear_sys_path, monkeypatch):
"""import from recipes dict should work, because create_runner_dict has sys.path.append"""
monkeypatch.setattr(
Coordinator,
"add_to_sys",
lambda x: x,
)
with pytest.raises(ModuleNotFoundError):
Coordinator.create_runner_dict(tmp_recipes)