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

Allure report doesn't take in correct number of tests when using parametrized tests where tests parameters are duplicated

Open qwertzy-antonio-godinho opened this issue 7 months ago • 4 comments

Describe the Bug Allure report doesn't take in correct number of tests when using parametrized tests where tests parameters are duplicated.

Steps to Reproduce

  1. Create a Python virtual env
  2. Install allure-pytest
  3. Create example tests to reproduce:

import pytest

@pytest.mark.parametrize( 'a, b', [
(1, 1), (1, 1) ] )

def test_one(a, b): assert a == b

  1. Run tests using pytest --clean-alluredir --alluredir=/tmp/allure-results
  2. Generate allure report allure generate /tmp/allure-results/ --clean --output /tmp/allure-results/allure-report --single-file
  3. Open Allure report

Expected Behaviour The report is generated without errors and the report shows 2 tests.

Screenshots or Additional Context Current version: Image pip freeze: allure-pytest==2.14.2 allure-python-commons==2.14.2 attrs==25.3.0 iniconfig==2.1.0 packaging==25.0 pluggy==1.6.0 pytest==8.3.5

Version 2.9.44 (expected working result): Image pip freeze: allure-pytest==2.9.44 allure-python-commons==2.9.44 attrs==25.3.0 iniconfig==2.1.0 packaging==25.0 pluggy==1.6.0 pytest==8.3.5 six==1.17.0

What Language are you using? Python 3.11.12

What Framework/Allure Integration you are using? Pytest

What version of Allure Integration you are using? 2.34.0

What version of Allure Report you are using? Latest

Code of Conduct I agree to follow this project's Code of Conduct

qwertzy-antonio-godinho avatar Jun 02 '25 12:06 qwertzy-antonio-godinho

Hi, @qwertzy-antonio-godinho, thanks for opening the issue.

Could you please clarify the use case behind having two identical sets of parameter values?

delatrie avatar Jun 09 '25 12:06 delatrie

Hi, @delatrie, hope you're well. The use case is that at work we use maps for different "products" (which at a later stage diverge in characteristics), but to the point, the issue that I'm reporting is that newer allure versions do not report on the correct number of tests ran by pytest like in previous version 2.9.44.

A better example of my use case would be something like:

from enum import Enum
import pytest

class Products(Enum):
    PRODUCT_1 = 'PROD_1'
    PRODUCT_2 = 'PROD_2'
    PRODUCT_3 = 'PROD_1'

@pytest.mark.parametrize(
    'a, b', 
    [    
        (Products.PRODUCT_1.value, 'PROD_1'), 
        (Products.PRODUCT_2.value, 'PROD_2'),
        (Products.PRODUCT_3.value, 'PROD_1'),
    ]
)

def test_one(a, b):
    assert a == b

There are 3 tests, but unfortunately Allure only shows 2 in the report (in our test suite to misses close to 200 tests).

Please see bellow: Image

When there are failures, Allure also does not report the correct number of failed tests:

Image

I think the issue could probably be related to this one: https://github.com/allure-framework/allure-python/issues/778

qwertzy-antonio-godinho avatar Jun 11 '25 14:06 qwertzy-antonio-godinho

@delatrie, hi! I have investigated this issue and tried a few solutions, but none of them work in every known case 🙁 Could you please take a look? Perhaps I’ve overlooked something, or maybe we could agree on a compromise.

  • To fix issue #778, we could include the parameter name and value used to calculate the historyId. Currently, we only use the value. However, this change would not solve the problem described here.
  • Another option would be to use item.callspec.id to calculate the historyId. However, this would break the fix for #744, where only the parameter id changes. Perhaps we can consider stopping support for that scenario?
  • I also tried using the parameter index (item.callspec.indices), but if the order of the test data changes, the historyId will be different and we won't be able to match the same test in the history, which doesn't feel right.

I’d be glad to hear any other ideas on how to solve this. I’m ready to finalize this work, prepare a PR, and update the tests. Thanks!

sharovd avatar Jun 15 '25 15:06 sharovd

Is this a new behaviour? I am using different ids for different tests, and I do not recall having missing tests in the allure report. I have been using them for quite a while. This is a simplified version of the test I was running:

import pytest
from random import random as rd

n = 100

@pytest.mark.parametrize("val", [round(rd(), 1) for _ in range(n)], ids=[f'Case{x}' for x in range(n)])
def test_foo(val):
    assert val < 0.5
Image Image

HenriqueMagnagoTyphoon avatar Oct 22 '25 20:10 HenriqueMagnagoTyphoon