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