Skip to content

Progression is wrong when using empty string in parametrized tests #6597

Open
@fcollonval

Description

@fcollonval

Description

Using a double decorator pytest.mark.parametrize with one of the value being "" (empty string) results in pytest not printing correctly the progress percentage.

It works:

  • If there is only one decorator
  • If the empty string is present only in one of the two parameter list
  • If customized ids not returning an empty string are used

Environment

Environment Conda
pytest 5.3.4 py36_0
python 3.6.9 h5500b2f_0

pytest and OS versions

Python 3.6.9 :: Anaconda, Inc.
Windows 10 64bits
pytest-5.3.4, py-1.8.1, pluggy-0.13.1

minimal example

Buggy

import pytest

@pytest.mark.parametrize("v", ["", " "])
@pytest.mark.parametrize("w", ["", " "])
def test_dummy(v, w):
    assert not v.strip()
    assert not w.strip()
pytest test_dummy.py -v
===== test session starts ===========================================
platform win32 -- Python 3.6.9, pytest-5.3.4, py-1.8.1, pluggy-0.13.1 -- python.exe
cachedir: .pytest_cache
rootdir:  
collected 4 items

test_dummy.py::test_dummy[] PASSED                               [ 25%]
test_dummy.py::test_dummy[ ] PASSED                              [ 50%]
test_dummy.py::test_dummy[ ] PASSED                              [ 50%]
test_dummy.py::test_dummy[ - ] PASSED                            [ 75%]

====== 4 passed in 0.03s ============================================

Working

import pytest

@pytest.mark.parametrize("v", ["", " "], ids=lambda a: f"'{a}'")
@pytest.mark.parametrize("w", ["", " "], ids=lambda a: f"'{a}'")
def test_dummy(v, w):
    assert not v.strip()
    assert not w.strip()
pytest test_dummy.py -v
===== test session starts ===========================================
platform win32 -- Python 3.6.9, pytest-5.3.4, py-1.8.1, pluggy-0.13.1 -- python.exe
cachedir: .pytest_cache
rootdir:  
collected 4 items

test_dummy.py::test_dummy[''-''] PASSED                                [ 25%]
test_dummy.py::test_dummy[''-' '] PASSED                               [ 50%]
test_dummy.py::test_dummy[' '-''] PASSED                               [ 75%]
test_dummy.py::test_dummy[' '-' '] PASSED                              [100%]

===== 4 passed in 0.03s ==================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: reportingrelated to terminal output and user-facing messages and errorstype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions