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

use __name__ attribute in the parametrize id for modules as well #6152

Merged
merged 4 commits into from
Nov 8, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ George Kussumoto
Georgy Dyuldin
Graham Horler
Greg Price
Gregory Lee
Grig Gheorghiu
Grigorii Eremeev (budulianin)
Guido Wesdorp
Expand Down
3 changes: 2 additions & 1 deletion src/_pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,8 @@ def _idval(val, argname, idx, idfn, item, config):
return ascii_escaped(val.pattern)
elif isinstance(val, enum.Enum):
return str(val)
elif (inspect.isclass(val) or inspect.isfunction(val)) and hasattr(val, "__name__"):
elif hasattr(val, "__name__") and isinstance(val.__name__, str):
# name of a class, function, module, etc.
return val.__name__
return str(argname) + str(idx)

Expand Down
15 changes: 15 additions & 0 deletions testing/test_mark.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,21 @@ def test_func(arg):
assert list(passed) == list(passed_result)


def test_parametrize_with_module(testdir):
testdir.makepyfile(
"""
import pytest
@pytest.mark.parametrize("arg", [pytest,])
def test_func(arg):
pass
"""
)
rec = testdir.inline_run()
passed, skipped, fail = rec.listoutcomes()
expected_id = "test_func[" + pytest.__name__ + "]"
assert passed[0].nodeid.split("::")[-1] == expected_id


@pytest.mark.parametrize(
"spec",
[
Expand Down