update fixtures in conftest, add --tests_dir and --session_id parser options
This commit is contained in:
parent
d4e9a50ca6
commit
0d1dd4ca17
1 changed files with 27 additions and 22 deletions
|
|
@ -1,47 +1,52 @@
|
||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from dirmanager import DirManager
|
||||||
from dotenv import dotenv_values
|
from dotenv import dotenv_values
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
parser.addoption(
|
parser.addoption(
|
||||||
"--env_file_path",
|
"--env_file",
|
||||||
|
action="store",
|
||||||
|
)
|
||||||
|
parser.addoption(
|
||||||
|
"--tests_dir",
|
||||||
|
action="store",
|
||||||
|
)
|
||||||
|
parser.addoption(
|
||||||
|
"--session_id",
|
||||||
action="store",
|
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]:
|
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)
|
dotenv_path = Path(dotenv_path)
|
||||||
assert dotenv_path.is_file()
|
assert dotenv_path.is_file()
|
||||||
return dotenv_values(dotenv_path)
|
return dotenv_values(dotenv_path)
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def session_id() -> str:
|
def RECORDS(dirmanager) -> Path:
|
||||||
current_datetime = datetime.now()
|
assert isinstance(dirmanager, DirManager)
|
||||||
return current_datetime.strftime("%Y-%m-%d-%H-%M")
|
return dirmanager.get_all_dirs()["records"]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def TEST_DIR(session_id) -> Path:
|
def STATES(dirmanager) -> Path:
|
||||||
all_tests_dir = Path("tests")
|
return dirmanager.get_all_dirs()["states"]
|
||||||
all_tests_dir.mkdir(exist_ok=True)
|
|
||||||
test_dir = all_tests_dir / Path(f"test_{session_id}")
|
|
||||||
test_dir.mkdir()
|
|
||||||
return test_dir
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
@pytest.fixture(scope="session", autouse=True)
|
||||||
def RECORDS(TEST_DIR) -> Path:
|
def RESULTS(dirmanager) -> Path:
|
||||||
records = TEST_DIR / Path("records")
|
return dirmanager.get_all_dirs()["results"]
|
||||||
return records.mkdir()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session", autouse=True)
|
|
||||||
def STATES(TEST_DIR) -> Path:
|
|
||||||
states = TEST_DIR / Path("states")
|
|
||||||
return states.mkdir()
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue