Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 7 commits into from Feb 16, 2024

Conversation

betapl3b
Copy link
Contributor

@betapl3b betapl3b commented Jan 2, 2024

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 betapl3b marked this pull request as ready for review January 2, 2024 17:21
Copy link
Contributor

@delatrie delatrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

allure-pytest/src/utils.py Outdated Show resolved Hide resolved
@betapl3b
Copy link
Contributor Author

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
Copy link
Contributor Author

betapl3b commented Feb 13, 2024

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 TvoroG/pytest-lazy-fixture#65 is the reason

@delatrie
Copy link
Contributor

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 #793 gets merged (a day or two, I believe).

Copy link
Contributor

@delatrie delatrie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#793 is merged.
Just one small grammar fix and we're good to go!

allure-pytest/examples/display_name/display_name.rst Outdated Show resolved Hide resolved
Co-authored-by: Maxim <17935127+delatrie@users.noreply.github.com>
@delatrie delatrie merged commit 2e7ecd7 into allure-framework:master Feb 16, 2024
10 checks passed
@betapl3b betapl3b deleted the param_id branch February 16, 2024 12:52
@delatrie delatrie self-assigned this Mar 1, 2024
IvanBuruyane pushed a commit to IvanBuruyane/allure-python that referenced this pull request Mar 19, 2024
…llure-framework#787)

Co-authored-by: Maxim <17935127+delatrie@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants