installable package #9
2 changed files with 25 additions and 23 deletions
|
|
@ -2,6 +2,7 @@
|
|||
# All fixtures in this file will be available without manual loading.
|
||||
|
||||
import os
|
||||
import re
|
||||
from imaplib import IMAP4_SSL
|
||||
from pathlib import Path
|
||||
|
||||
|
|
@ -11,6 +12,7 @@ from playwright.sync_api import BrowserContext, expect
|
|||
from pytest import Parser
|
||||
|
||||
from pytest_abra.dir_manager import DirManager
|
||||
from pytest_abra.env_manager import EnvFile
|
||||
from pytest_abra.utils import BaseUrl
|
||||
|
||||
# global timeout and LOCALE
|
||||
|
|
@ -30,21 +32,12 @@ def context(context: BrowserContext) -> BrowserContext:
|
|||
|
||||
|
||||
def pytest_addoption(parser: Parser):
|
||||
parser.addoption(
|
||||
"--env_file",
|
||||
action="store",
|
||||
)
|
||||
parser.addoption(
|
||||
"--output_dir",
|
||||
action="store",
|
||||
)
|
||||
parser.addoption(
|
||||
"--session_id",
|
||||
action="store",
|
||||
)
|
||||
parser.addoption("--runner_index", action="store", type=int)
|
||||
parser.addoption("--output_dir", action="store", type=Path)
|
||||
parser.addoption("--session_id", action="store", type=str)
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
@pytest.fixture(scope="session")
|
||||
def DIR(request) -> DirManager:
|
||||
"""Fixture holding test directories
|
||||
|
||||
|
|
@ -56,7 +49,6 @@ def DIR(request) -> DirManager:
|
|||
|
||||
output_dir = request.config.getoption("--output_dir")
|
||||
assert output_dir, "pytest argument --output_dir not set"
|
||||
output_dir = Path(output_dir)
|
||||
session_id = request.config.getoption("--session_id")
|
||||
assert session_id, "pytest argument --session_id not set"
|
||||
dirmanager = DirManager(output_dir=output_dir, session_id=session_id)
|
||||
|
|
@ -65,12 +57,22 @@ def DIR(request) -> DirManager:
|
|||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def dotenv_config(request) -> dict[str, str]:
|
||||
dotenv_path = request.config.getoption("--env_file")
|
||||
assert dotenv_path, "pytest argument --dotenv_path not set"
|
||||
dotenv_path = Path(dotenv_path)
|
||||
assert dotenv_path.is_file()
|
||||
return dotenv_values(dotenv_path) # type: ignore
|
||||
def ENV_FILES(DIR: DirManager) -> dict[int, EnvFile]:
|
||||
out: dict[int, EnvFile] = dict()
|
||||
for env_path in DIR.ENV_FILES.glob("*.env"):
|
||||
config: dict[str, str] = dotenv_values(env_path) # type: ignore
|
||||
env_type = config["TYPE"]
|
||||
result = re.search(r"(\d+)-*", env_path.name)
|
||||
assert result
|
||||
runner_index = int(result[1])
|
||||
out[runner_index] = EnvFile(env_path=env_path, config=config, env_type=env_type)
|
||||
return out
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def dotenv_config(request, ENV_FILES: dict[int, EnvFile]) -> dict[str, str]:
|
||||
runner_index = request.config.getoption("--runner_index")
|
||||
return ENV_FILES[runner_index].config
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
|
|
|
|||
|
|
@ -123,8 +123,8 @@ class Runner:
|
|||
# command_arguments.append("-rx")
|
||||
command_arguments.append(str(full_test_path))
|
||||
|
||||
command_arguments.append("--env_file")
|
||||
command_arguments.append(str(self.dotenv_path))
|
||||
command_arguments.append("--runner_index")
|
||||
command_arguments.append(str(self.runner_index))
|
||||
|
||||
# set root dir for tests output (used in DirManager). this is our custom argument
|
||||
command_arguments.append("--output_dir")
|
||||
|
|
@ -146,7 +146,7 @@ class Runner:
|
|||
# command_arguments.append("on")
|
||||
|
||||
# Disable capturing. With -s set, prints will go to console as if pytest is not there.
|
||||
# command_arguments.append("-s")
|
||||
command_arguments.append("-s")
|
||||
|
||||
# headed
|
||||
# command_arguments.append("--headed")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue