Merge pull request #4196 from nicoddemus/better-signature-error-msg-4026
Improve error message when it is not possible to determine a function's signature
This commit is contained in:
commit
dc0b4efffa
|
@ -0,0 +1 @@
|
||||||
|
Improve error message when it is not possible to determine a function's signature.
|
|
@ -13,7 +13,7 @@ from contextlib import contextmanager
|
||||||
import py
|
import py
|
||||||
|
|
||||||
import _pytest
|
import _pytest
|
||||||
from _pytest.outcomes import TEST_OUTCOME
|
from _pytest.outcomes import TEST_OUTCOME, fail
|
||||||
from six import text_type
|
from six import text_type
|
||||||
import six
|
import six
|
||||||
|
|
||||||
|
@ -131,9 +131,17 @@ def getfuncargnames(function, is_method=False, cls=None):
|
||||||
# ordered mapping of parameter names to Parameter instances. This
|
# ordered mapping of parameter names to Parameter instances. This
|
||||||
# creates a tuple of the names of the parameters that don't have
|
# creates a tuple of the names of the parameters that don't have
|
||||||
# defaults.
|
# 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(
|
arg_names = tuple(
|
||||||
p.name
|
p.name
|
||||||
for p in signature(function).parameters.values()
|
for p in parameters.values()
|
||||||
if (
|
if (
|
||||||
p.kind is Parameter.POSITIONAL_OR_KEYWORD
|
p.kind is Parameter.POSITIONAL_OR_KEYWORD
|
||||||
or p.kind is Parameter.KEYWORD_ONLY
|
or p.kind is Parameter.KEYWORD_ONLY
|
||||||
|
|
|
@ -952,3 +952,23 @@ def test_collect_init_tests(testdir):
|
||||||
"*<Function 'test_foo'>",
|
"*<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"]
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue