Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 changelog/4026.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error message when it is not possible to determine a function's signature.
12 changes: 10 additions & 2 deletions src/_pytest/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import py

import _pytest
from _pytest.outcomes import TEST_OUTCOME
from _pytest.outcomes import TEST_OUTCOME, fail
from six import text_type
import six

Expand Down Expand Up @@ -131,9 +131,17 @@ def getfuncargnames(function, is_method=False, cls=None):
# ordered mapping of parameter names to Parameter instances. This
# creates a tuple of the names of the parameters that don't have
# defaults.
try:
parameters = signature(function).parameters
except (ValueError, TypeError) as e:
fail(
"Could not determine arguments of {!r}: {}".format(function, e),
pytrace=False,
)

arg_names = tuple(
p.name
for p in signature(function).parameters.values()
for p in parameters.values()
if (
p.kind is Parameter.POSITIONAL_OR_KEYWORD
or p.kind is Parameter.KEYWORD_ONLY
Expand Down
20 changes: 20 additions & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,23 @@ def test_collect_init_tests(testdir):
"*<Function 'test_foo'>",
]
)


def test_collect_invalid_signature_message(testdir):
"""Check that we issue a proper message when we can't determine the signature of a test
function (#4026).
"""
testdir.makepyfile(
"""
import pytest

class TestCase:
@pytest.fixture
def fix():
pass
"""
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
["Could not determine arguments of *.fix *: invalid method signature"]
)