Skip to content

Invalid signature in class fixture causes difficult-to-debug error #4026

@asottile

Description

@asottile

minimal reproduction

import pytest


class TestCase:
    @pytest.fixture(autouse=True)
    def fix():  # XXX: should have `self`
        pass

output (python2)

$ pytest t.py
============================= test session starts ==============================
platform linux2 -- Python 2.7.15rc1, pytest-3.8.1, py-1.6.0, pluggy-0.7.1
rootdir: /tmp, inifile:
collected 0 items / 1 errors                                                   

==================================== ERRORS ====================================
____________________________ ERROR collecting t.py _____________________________
venv/local/lib/python2.7/site-packages/funcsigs/__init__.py:71: in signature
    raise ValueError('invalid method signature')
E   ValueError: invalid method signature
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.11 seconds ============================

output (python3)

$ pytest t.py 
============================= test session starts ==============================
platform linux -- Python 3.6.5, pytest-3.8.1, py-1.6.0, pluggy-0.7.1
rootdir: /tmp, inifile:
collected 0 items / 1 errors                                                   

==================================== ERRORS ====================================
____________________________ ERROR collecting t.py _____________________________
/usr/lib/python3.6/inspect.py:3037: in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
/usr/lib/python3.6/inspect.py:2787: in from_callable
    follow_wrapper_chains=follow_wrapped)
/usr/lib/python3.6/inspect.py:2198: in _signature_from_callable
    return _signature_bound_method(sig)
/usr/lib/python3.6/inspect.py:1788: in _signature_bound_method
    raise ValueError('invalid method signature')
E   ValueError: invalid method signature
!!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!!!
=========================== 1 error in 0.30 seconds ============================
$ pip freeze --all
atomicwrites==1.2.1
attrs==18.2.0
funcsigs==1.0.2
future-fstrings==0.4.4
more-itertools==4.3.0
pathlib2==2.3.2
pip==18.0
pluggy==0.7.1
py==1.6.0
pytest==3.8.1
scandir==1.9.0
setuptools==40.4.3
six==1.11.0
tokenize-rt==2.0.1
wheel==0.31.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: collectionrelated to the collection phasetype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions