allure-python icon indicating copy to clipboard operation
allure-python copied to clipboard

Test's name contains dict's value instead of dict's key in allure

Open HeikKerimov opened this issue 6 years ago • 6 comments

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: screenshot

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 avatar Jan 17 '19 11:01 HeikKerimov

@HeikKerimov hi, can you provide runnable code?

sseliverstov avatar Jan 25 '19 11:01 sseliverstov

@sseliverstov test

data

allure

HeikKerimov avatar Mar 13 '19 08:03 HeikKerimov

@sseliverstov screenshot-ci a-2019 03 15-09-36-40

HeikKerimov avatar Mar 15 '19 06:03 HeikKerimov

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 image

rad96 avatar Dec 02 '20 22:12 rad96

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} <-")

image

It works with metafunc.parametrize as well.

delatrie avatar Dec 16 '22 12:12 delatrie

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}).

joaonc avatar Feb 01 '23 23:02 joaonc