e2e_tests/tests/test_coordinator.py
Daniel 0fafa22272 cleanup (#18)
- remove demo runner

- improve docs

- rename all tests to test_* (previously, also setup_* and cleanup_* existed) to improve stability as it is not guaranteed that pytest.ini is loaded.

- improve logging formatting

- improve full integration test

Reviewed-on: local-it-infrastructure/e2e_tests#18
Co-authored-by: Daniel <d.brummerloh@gmail.com>
Co-committed-by: Daniel <d.brummerloh@gmail.com>
2023-12-15 17:57:48 +01:00

53 lines
1.5 KiB
Python

import os
import shutil
import sys
from pathlib import Path
import pytest
from pytest_abra.coordinator import Coordinator
from pytest_abra.dir_manager import DirManager
def test_load_test_credentials(tmp_path: Path):
assert "TEST_USER" not in os.environ
DIR = DirManager(output_dir=tmp_path, session_id="abc")
DIR.create_all_dirs()
Coordinator.load_test_credentials(DIR)
assert (DIR.STATES / "credentials_test.json").is_file()
assert "TEST_USER" in os.environ
test_user_before = os.environ["TEST_USER"]
# os.environ.clear() # this breaks pytest!
del os.environ["TEST_USER"]
assert "TEST_USER" not in os.environ
Coordinator.load_test_credentials(DIR)
assert test_user_before == os.environ["TEST_USER"]
@pytest.fixture(scope="session")
def tmp_recipes(tmp_path_factory: pytest.TempPathFactory) -> Path:
tmp_recipes_target = tmp_path_factory.mktemp("recipes")
recipes_dir_source = Path("recipes")
shutil.copytree(recipes_dir_source, tmp_recipes_target, dirs_exist_ok=True)
return tmp_recipes_target
@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(tmp_recipes: Path, clear_sys_path):
"""import from recipes dict should work, because create_runner_dict has sys.path.append"""
RUNNER_DICT = Coordinator.create_runner_dict(tmp_recipes)
assert len(RUNNER_DICT.keys()) > 0