|
6 | 6 |
|
7 | 7 | load_dotenv() |
8 | 8 |
|
9 | | -# Map test function names to QA Sphere-friendly display names with BD-XXX markers. |
10 | | -# qas-cli matches markers in the format PROJECT-SEQUENCE (e.g. BD-023). |
11 | | -_QAS_NAMES: dict[str, str] = { |
12 | | - "test_bd023_cart_operations": "BD-023: Cart operations", |
13 | | - "test_bd022_order_with_cash_payment": "BD-022: Order with cash payment", |
14 | | - "test_bd055_about_page_content": "BD-055: About page content", |
15 | | - "test_bd026_navbar_navigation_state": "BD-026: Navbar navigation state", |
16 | | - "test_bd038_menu_tabs_and_products": "BD-038: Menu tabs and products", |
17 | | - "test_bd052_welcome_banner": "BD-052: Welcome banner", |
18 | | -} |
| 9 | +# QA Sphere project code. Used to detect test case markers in function names. |
| 10 | +# e.g. test_bd023_cart_operations -> BD-023:test_bd023_cart_operations |
| 11 | +QAS_PROJECT_CODE = "BD" |
| 12 | + |
| 13 | +_QAS_MARKER_RE = re.compile(rf"test_({QAS_PROJECT_CODE})(\d+)_", re.IGNORECASE) |
| 14 | + |
| 15 | + |
| 16 | +def _rewrite_qas_name(name: str) -> str: |
| 17 | + """Rewrite test name to include QA Sphere marker prefix. |
| 18 | +
|
| 19 | + test_bd023_cart_operations[chromium] -> BD-023:test_bd023_cart_operations[chromium] |
| 20 | + """ |
| 21 | + m = _QAS_MARKER_RE.match(name) |
| 22 | + if not m: |
| 23 | + return name |
| 24 | + code = m.group(1).upper() |
| 25 | + seq = m.group(2) |
| 26 | + return f"{code}-{seq}:{name}" |
19 | 27 |
|
20 | 28 |
|
21 | 29 | def pytest_itemcollected(item: pytest.Item) -> None: |
22 | | - """Rewrite test node IDs so JUnit XML contains QA Sphere markers (BD-XXX).""" |
23 | | - # item.name looks like "test_bd023_cart_operations[chromium]" |
24 | | - base_name = re.sub(r"\[.*\]$", "", item.name) |
25 | | - if base_name in _QAS_NAMES: |
26 | | - suffix = item.name[len(base_name) :] # e.g. "[chromium]" |
27 | | - item._nodeid = item._nodeid.replace(item.name, _QAS_NAMES[base_name] + suffix) |
28 | | - item.name = _QAS_NAMES[base_name] + suffix |
| 30 | + """Rewrite test node IDs so JUnit XML contains QA Sphere markers.""" |
| 31 | + new_name = _rewrite_qas_name(item.name) |
| 32 | + if new_name != item.name: |
| 33 | + item._nodeid = item._nodeid.replace(item.name, new_name) |
| 34 | + item.name = new_name |
29 | 35 |
|
30 | 36 |
|
31 | 37 | @pytest.fixture(scope="session") |
|
0 commit comments