allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
722 stars 236 forks source link

Add pytest ParameterSet.id placeholder for @allure.title formatter #787

Closed betapl3b closed 7 months ago

betapl3b commented 9 months ago

Context

Currently, to use ParameterSet.id (pytest.param(id=*)) in allure.title you need to use the request fixture in combination with the allure.dynamic.title function. Thus, the complete design looks like this:

@pytest.mark.parametrize("name", [pytest.param("value", id="some id")])
def test_1(request)
    allure.dynamic.title(f"Test name with id = {request.node.callspec.id}")
    ...

My fix suggests using the following syntax:

@pytest.mark.parametrize("name", [pytest.param("value", id="some id")])
@allure.title("Test name with id = {param_id}")
def test_1()
    ...

Since many people already assign identifiers to their parameter sets, this syntax will save them from duplicating code. And it will also help avoid situations where a test fails before allure.dynamic.title is executed and the test result is left without DisplayName.

Checklist

betapl3b commented 7 months ago

Hi, @betapl3b ! Sorry for taking it so long.

Thanks for your contribution. The feature is nice to have, and I'm okay with pre-defined variables in that context.

The only thing I would ask you to change is to make the pre-defined variable overwritable by an explicit argument of a test (an extra test for that behavior would also be nice to have). See my comment for the example.

Hello! Thank you for your feedback. It makes sense!

betapl3b commented 7 months ago

Hi @delatrie, the changes in the pytest 8.0.0 release seem to break the tests. I tested them locally using the previous version (pytest 7.4.4) and they work fine. What do you do in these cases? Should we fix the requirements to prevent pytest 8.0.0 from being updated?

P.S. seems like https://github.com/TvoroG/pytest-lazy-fixture/issues/65 is the reason

delatrie commented 7 months ago

I don't think we should refrain from testing against the most recent version of pytest. It's unlikely the issue will be fixed soon (if at all) in lazy-fixture. Let's wait until allure-framework/allure-python#793 gets merged (a day or two, I believe).