-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
We have a test case @src/tests/fixtures/junit-xml/pytest-style.xml
<?xml version="1.0" encoding="utf-8"?>
<testsuites name="pytest tests">
<testsuite name="pytest" errors="0" failures="1" skipped="0" tests="4" time="3.5" timestamp="2026-02-09T12:00:00.000000+00:00" hostname="test-host">
<testcase classname="tests.login_test.TestLogin" name="TEST-002 test_valid_login[chromium]" time="0.649">
</testcase>
<testcase classname="tests.login_test.TestLogin" name="TEST-003 test_login_error[chromium-invalid_password]" time="0.625">
</testcase>
<testcase classname="tests.checkout_test.TestCheckout" name="TEST-004 test_checkout_counter[chromium-standard_user]" time="0.988">
</testcase>
<testcase classname="tests.inventory_test.TestInventory" name="TEST-006 test_inventory_page[chromium-standard_user]" time="0.584">
<failure message="AssertionError: expected True but got False">self = <tests.inventory_test.TestInventory object>
def test_inventory_page(self, page) -> None:
> assert page.title() == "Expected Title"
E AssertionError: expected True but got False
tests/inventory_test.py:12: AssertionError</failure>
</testcase>
<testcase classname="tests.inventory_test.TestInventory" name="TEST-007 test_inventory_sort[chromium-standard_user]" time="0.734">
</testcase>
</testsuite>
</testsuites>
where we have assumed that its possible to have the QA Sphere markers with dash (-) (e.g. TEST-002) are possible as prefix.
Claude pointed out that it might be possible to do this
pytest JUnit XML reports can have dashes in the name attribute. Here's how:
- Parametrize IDs (most common for dashes)
@pytest.mark.parametrize("user", ["std"], ids=["chromium-standard_user"])
def test_checkout_counter(self, user):
...
This produces test_checkout_counter[chromium-standard_user] in the XML — the part in brackets can contain dashes freely.
- The TEST-002 marker prefix
Python function names can't contain dashes, so the TEST-002 test_valid_login[chromium] format from your fixture requires prepending the marker to the test name. Common approaches:
- Custom conftest hook that renames tests in the XML output:
# conftest.py
def pytest_itemcollected(item):
marker = item.get_closest_marker("qas")
if marker:
item._nodeid = f"{marker.args[0]} {item.nodeid}"
- with usage: @pytest.mark.qas("TEST-002")
- Putting the marker directly in the test name using underscores like test_TEST_002_valid_login — but that uses underscores, not dashes.
- A custom plugin / conftest that modifies record_property or uses the junit_family=xunit2 format.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels