Pytest: easier pattern for linter-friendly local fixtures

Created on 23 Jul 2019  路  3Comments  路  Source: pytest-dev/pytest

1444 added a linter-friendly way to deal with locally defined fixtures, but it's rather cumbersome.

I'd like to see the fixture decorator ignore any leading underscore of the wrapped function. Then usage would be:

@pytest.fixture
def _my_fixture():
    ...

def test_foo(my_fixture):
    ...
fixtures proposal

Most helpful comment

I'm against adding a implicit name mangling system

All 3 comments

I'm against adding a implicit name mangling system

I can appreciate the aversion to implicitness-- however the fixture scheme is already rather implicit itself. I mean, define a function and then functions with an argument of the same name invoke it as a (stateful) factory...?

Prefixing local functions with underbar is the right thing to do anyway. The small renaming doesn't seem like a stretch.

@belm0
What linter is this about?
Maybe it should be made aware of pytest fixtures then maybe?

Prefixing local functions with underbar is the right thing to do anyway.

..if "unused" only I assume?

Was this page helpful?
0 / 5 - 0 ratings