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

None in paramtrized test id will use automatically generated id #1468

Conversation

palaviv
Copy link
Contributor

@palaviv palaviv commented Mar 20, 2016

This pull request is allowing the user to pass None as a specific test id of parametrize. If a test id is None the specific test id will be automatically calculated.

import pytest
@pytest.mark.parametrize(("a,b"), [(1,1), (1,1), (1,2)],
                         ids=["basic", None, "advanced"])  
def test_function(a, b):
    assert a == b

This will result in the following tests:

  • test_function[basic]
  • test_function[1-1]
  • test_function[advanced]

As a side effect of this PR i noticed that when you pass the same test id we recieve a duplicate test:

import pytest
@pytest.mark.parametrize("a,b", [(1,2), (3,4)], ids=["a", "a"])
def test_a(a,b):
    pass

Currently result in the test:
- test_a[a]
- test_a[a]

After this change the result will be:
- test_a[0a]
- test_a[1a]

Same as when a ids callable return the same value.

@RonnyPfannschmidt
Copy link
Member

excellent work, as followup we might want to take a look at where to put the prefix

RonnyPfannschmidt added a commit that referenced this pull request Mar 20, 2016
None in paramtrized test id will use automatically generated id
@RonnyPfannschmidt RonnyPfannschmidt merged commit da10451 into pytest-dev:features Mar 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants