new test framework #1

Merged
dan merged 47 commits from wip-new-framework into dev 2023-11-22 21:40:14 +01:00
Showing only changes of commit 0d1dd4ca17 - Show all commits

View file

@ -1,47 +1,52 @@
from datetime import datetime
from pathlib import Path
import pytest
from dirmanager import DirManager
from dotenv import dotenv_values
def pytest_addoption(parser):
parser.addoption(
"--env_file_path",
"--env_file",
action="store",
)
parser.addoption(
"--tests_dir",
action="store",
)
parser.addoption(
"--session_id",
action="store",
)
@pytest.fixture
@pytest.fixture(scope="session", autouse=True)
def dirmanager(request) -> DirManager:
tests_dir = request.config.getoption("--tests_dir")
tests_dir = Path(tests_dir)
session_id = request.config.getoption("--session_id")
return DirManager(tests_dir=tests_dir, session_id=session_id)
@pytest.fixture(scope="session", autouse=True)
def dotenv_config(request) -> dict[str, str]:
dotenv_path = request.config.getoption("--env_file_path")
dotenv_path = request.config.getoption("--env_file")
dotenv_path = Path(dotenv_path)
assert dotenv_path.is_file()
return dotenv_values(dotenv_path)
@pytest.fixture(scope="session", autouse=True)
def session_id() -> str:
current_datetime = datetime.now()
return current_datetime.strftime("%Y-%m-%d-%H-%M")
def RECORDS(dirmanager) -> Path:
assert isinstance(dirmanager, DirManager)
return dirmanager.get_all_dirs()["records"]
@pytest.fixture(scope="session", autouse=True)
def TEST_DIR(session_id) -> Path:
all_tests_dir = Path("tests")
all_tests_dir.mkdir(exist_ok=True)
test_dir = all_tests_dir / Path(f"test_{session_id}")
test_dir.mkdir()
return test_dir
def STATES(dirmanager) -> Path:
return dirmanager.get_all_dirs()["states"]
@pytest.fixture(scope="session", autouse=True)
def RECORDS(TEST_DIR) -> Path:
records = TEST_DIR / Path("records")
return records.mkdir()
@pytest.fixture(scope="session", autouse=True)
def STATES(TEST_DIR) -> Path:
states = TEST_DIR / Path("states")
return states.mkdir()
def RESULTS(dirmanager) -> Path:
return dirmanager.get_all_dirs()["results"]