new test framework #1
1 changed files with 27 additions and 22 deletions
|
|
@ -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"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue