Skip to content

staticmethod tests don't work with fixtures #2699

@nicoddemus

Description

@nicoddemus

Original post by @ceridwen in this comment:


I was attempting to use this, and it doesn't seem to be working quite right with fixtures. Running the following code,

import pytest

@pytest.fixture
def foo():
    return 'foo'

def test_foo(foo):
    assert foo == 'foo'

class TestFoo:
    @staticmethod
    def test_foo(foo):
        assert foo == 'foo'

Produces the following error:

pyfuncitem = <Function 'test_foo'>

    @hookimpl(trylast=True)
    def pytest_pyfunc_call(pyfuncitem):
        testfunction = pyfuncitem.obj
        if pyfuncitem._isyieldedfunction():
            testfunction(*pyfuncitem._args)
        else:
            funcargs = pyfuncitem.funcargs
            testargs = {}
            for arg in pyfuncitem._fixtureinfo.argnames:
                testargs[arg] = funcargs[arg]
>           testfunction(**testargs)
E           TypeError: test_foo() missing 1 required positional argument: 'foo'

../../Library/Python/3.6/lib/python/site-packages/_pytest/python.py:143: TypeError
======================= 1 failed, 1 passed in 0.32 seconds =======================

The first test_foo() function passes correctly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: 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