Fix setup report folders to use product and flow
This commit is contained in:
+32
-9
@@ -5,15 +5,15 @@ import json
|
||||
from tests.browser import create_chrome_driver
|
||||
|
||||
|
||||
def get_run_id(config):
|
||||
def get_run_id(config, prefix=None):
|
||||
|
||||
run_id = getattr(config, "_pxil_run_id", None)
|
||||
if run_id:
|
||||
return run_id
|
||||
run_prefix = prefix or _get_run_prefix(config)
|
||||
run_ids = getattr(config, "_pxil_run_ids", {})
|
||||
if run_prefix in run_ids:
|
||||
return run_ids[run_prefix]
|
||||
|
||||
base_folder = os.path.join("reports", "screenshots")
|
||||
os.makedirs(base_folder, exist_ok=True)
|
||||
run_prefix = _get_run_prefix(config)
|
||||
|
||||
existing = [
|
||||
name for name in os.listdir(base_folder)
|
||||
@@ -28,10 +28,11 @@ def get_run_id(config):
|
||||
for name in existing
|
||||
if name.split("_")[-1].isdigit()
|
||||
]
|
||||
next_number = max(numbers) + 1
|
||||
next_number = max(numbers, default=0) + 1
|
||||
|
||||
run_id = f"{run_prefix}_{next_number:03d}"
|
||||
config._pxil_run_id = run_id
|
||||
run_ids[run_prefix] = run_id
|
||||
config._pxil_run_ids = run_ids
|
||||
return run_id
|
||||
|
||||
|
||||
@@ -66,7 +67,7 @@ def driver():
|
||||
@pytest.fixture
|
||||
def test_context(request):
|
||||
|
||||
test_id = get_run_id(request.config)
|
||||
test_id = get_run_id(request.config, _setup_item_prefix(request.node))
|
||||
test_name = request.node.name
|
||||
|
||||
folder = os.path.abspath(
|
||||
@@ -201,9 +202,28 @@ def _build_steps_html(steps):
|
||||
)
|
||||
|
||||
|
||||
def _setup_item_prefix(item):
|
||||
"""Use the collected product and flow, including when -k selects a subset."""
|
||||
nodeid = item.nodeid.replace("\\", "/")
|
||||
if "tests/setup/" not in nodeid:
|
||||
return None
|
||||
callspec = getattr(item, "callspec", None)
|
||||
product_config = callspec.params.get("config") if callspec else None
|
||||
if not isinstance(product_config, dict):
|
||||
return None
|
||||
product = product_config["product_name"].upper()
|
||||
if "test_combined_setup.py" in nodeid:
|
||||
return f"{product}_SESSION_TOKEN"
|
||||
if "/sessions/" in nodeid:
|
||||
return f"{product}_SESSION"
|
||||
if "/tokens/" in nodeid:
|
||||
return f"{product}_TOKEN"
|
||||
return f"{product}_SETUP"
|
||||
|
||||
|
||||
def _get_run_prefix(config):
|
||||
|
||||
invocation_args = " ".join(str(arg) for arg in config.invocation_params.args).lower()
|
||||
invocation_args = " ".join(str(arg) for arg in config.invocation_params.args).replace("\\", "/").lower()
|
||||
|
||||
if "tests/setup/sessions" in invocation_args or "test_session.py" in invocation_args:
|
||||
return "PXIL_SESSION"
|
||||
@@ -211,6 +231,9 @@ def _get_run_prefix(config):
|
||||
if "tests/setup/tokens" in invocation_args or "test_trading_token.py" in invocation_args:
|
||||
return "PXIL_TOKEN"
|
||||
|
||||
if "tests/setup" in invocation_args or "test_combined_setup.py" in invocation_args:
|
||||
return "PXIL_SETUP"
|
||||
|
||||
runtime_path = os.path.abspath(os.path.join("config", "runtime.json"))
|
||||
if os.path.exists(runtime_path):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user