71 lines
2 KiB
Python
71 lines
2 KiB
Python
# regarding conftest:
|
|
# If you have conftest.py files which do not reside in a python package directory
|
|
# (i.e. one containing an __init__.py) then “import conftest” can be ambiguous
|
|
# because there might be other conftest.py files as well on your PYTHONPATH or
|
|
# sys.path. It is thus good practise for projects to either put conftest.py under
|
|
# a package scope or to never import anything from a conftest.py file.
|
|
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from dotenv import dotenv_values
|
|
from playwright.sync_api import BrowserContext, expect
|
|
from pytest import Parser
|
|
|
|
from src.dirmanager import DirManager
|
|
|
|
# global timeout and LOCALE
|
|
LOCALE = {"Accept-Language": "de_DE"}
|
|
TIMEOUT = 10_000
|
|
expect.set_options(timeout=TIMEOUT)
|
|
|
|
|
|
@pytest.fixture
|
|
def context(context: BrowserContext) -> BrowserContext:
|
|
context.set_default_timeout(TIMEOUT)
|
|
context.set_extra_http_headers(LOCALE)
|
|
return context
|
|
|
|
|
|
def pytest_addoption(parser: Parser):
|
|
parser.addoption(
|
|
"--env_file",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
parser.addoption(
|
|
"--output_dir",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
parser.addoption(
|
|
"--session_id",
|
|
action="store",
|
|
required=True,
|
|
)
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def DIR(request) -> DirManager:
|
|
"""Fixture holding test directories
|
|
|
|
DIR.OUTPUT
|
|
DIR.SESSION
|
|
DIR.RECORDS
|
|
DIR.STATES
|
|
DIR.RESULTS"""
|
|
|
|
output_dir = request.config.getoption("--output_dir")
|
|
output_dir = Path(output_dir)
|
|
session_id = request.config.getoption("--session_id")
|
|
dirmanager = DirManager(output_dir=output_dir, session_id=session_id)
|
|
dirmanager.create_all_dirs()
|
|
return dirmanager
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def dotenv_config(request) -> dict[str, str]:
|
|
dotenv_path = request.config.getoption("--env_file")
|
|
dotenv_path = Path(dotenv_path)
|
|
assert dotenv_path.is_file()
|
|
return dotenv_values(dotenv_path) # type: ignore
|