allure-python
allure-python copied to clipboard
Test's name contains dict's value instead of dict's key in allure
Stack: python, pytest, selenium.
To parametrize tests I use pytest_generate_tests:
metafunc.parametrize(fixture, test_data.values(), ids=[key for key, value in test_data.items()])
In allure test looks like this:
But in IDE (Pycharm) it looks as it should be:
test_home_page.py::test_add_not_existing_product[Hot products]
Is it possible to show dict's key in allure too?
@HeikKerimov hi, can you provide runnable code?
@sseliverstov
@sseliverstov
Checked out this issue on: Python 3.9.0+, pytest-6.1.2, allure-pytest-2.8.22, allure 2.13.7
conftest:
test_data = {"key1": "value1", "key2": "value2"}
def pytest_generate_tests(metafunc):
if 'fix' in metafunc.fixturenames:
metafunc.parametrize('fix', test_data.values(), ids=[key for key, value in test_data.items()])
test_test.py:
import pytest
@pytest.fixture
def fix():
pass
def test_test(fix):
pass
Looks like it works as intended now
Currently, only parameter`s value could be inserted into a test title using the @allure.title
decorator.
Inserting a key of a parameter set through the decorator is not supported now. But you can always set the title dynamically, adding whatever you want:
import allure
import pytest
@pytest.mark.parametrize("v", ["Value 1", "Value 2"], ids=["key-1", "key-2"])
def test_function(request, v):
allure.dynamic.title(f"Test {request.node.callspec.id} <-")
It works with metafunc.parametrize
as well.
IMO, if the id
of the parameter is set, then use that. Otherwise, use the value.
Another idea is to use {param.value}
and {param.id}
, where {param.value
behaves like the current param
, ex:
@pytest.mark.parametrize('p', [1, 2], ids=['foo', 'bar'])
@allure.title('The title - {p.id}')
def test_something(p):
...
The workaround suggested is a bit clunky and this seems like an easy fix.
Also, to maintain backwards compatibility, if only using {param}
(without the .value
or .id
), then it would behave as {param.value}
).