[pytest-dev] Custom test collection with fixtures

Sterling Paramore gnilrets at gmail.com
Fri Jan 12 18:51:03 EST 2018


I'm trying to build a plugin that will do something "special" with test
functions that are prefixed with "case_".  However, I'm having trouble
collecting those and using them with fixtures.

in conftest.py I have

def pytest_pycollect_makeitem(collector, name, obj):
    if inspect.isfunction(obj) and (name.startswith('case_'):
        Function = collector._getcustomclass("Function")
        return Function(name, parent=collector)

and in test_mything.py I have:

class TestSomething():
    @pytest.fixture
    def scenario(self):
        pass

    def case_1(self, scenario):
        pass

But when I run the test, I get an error "TypeError: case_1() missing 1
required positional argument: 'scenario'"

How can I create the item so that it runs with the specific fixtures?

Thanks,
Sterling
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pytest-dev/attachments/20180112/6cf3cc7e/attachment.html>


More information about the pytest-dev mailing list