question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Progression is wrong when using empty string in parametrized tests

See original GitHub issue

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 ==================================================

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
blueyedcommented, Jan 28, 2020

@RonnyPfannschmidt Agreed. When fixing nodeid generation in this case the test with #6599 would need to be adjusted then - or should get adjusted probably already.

0reactions
blueyedcommented, Feb 28, 2020

@bluetech I think https://github.com/pytest-dev/pytest/pull/6599 is still a valid fix for this particular issue, although the trigger has been fixed also already.

“Globally guarantee uniqueness of nodeids” is a valid issue, but should be taken out of here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JUnit 5 Tutorial: Writing Parameterized Tests - Petri Kainulainen
This blog post describes how we can write parameterized tests with JUnit 5. After we have finished this blog post, we:.
Read more >
Testing null, empty, blank - ngeor.com
The only problem here is that the method is defined as a string, which means you lose the compile-time safety. If you rename...
Read more >
Create multiple parameter sets in one parameterized class ...
I have no affiliation with Pragmatists, I just found this a few days ago. This framework runs on top of JUnit and handles...
Read more >
Java Unit Testing with JUnit and TestNG
JUnit 4 introduces parameterized test which allows you to run the same test over and over again using different values. To use parameterized...
Read more >
JUnit 5 User Guide
Denotes that a method is a parameterized test. ... integration tests or functional tests where the sequence of the tests is important, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found