[pytest-dev] fixtures and pylint W0621
holger at merlinux.eu
Wed Dec 4 07:26:55 CET 2013
On Wed, Dec 04, 2013 at 13:29 +1100, Brianna Laugher wrote:
> On 3 December 2013 18:39, holger krekel <holger at merlinux.eu> wrote:
> > Right, it seems that when we introduced @pytest.fixture we decided you can
> > either use the prefix or the marker. That could be lifted but i wonder
> > if we should rather go for a different convention because pytest_funcarg__
> > is not a beautiful prefix. What do you think of pytest stripping the "__" prefix?
> > @pytest.fixture
> > def __foo2(monkeypatch):
> > return monkeypatch
> > This fixture would become accessible via the "foo2" name. Using "__foo2"
> > would yield a lookup error and the error would indicate there is a "foo2"
> > available. If you don't like it, any other suggestions?
> Hmm. My main concern here would be that fixture definitions are easily
> 'findable' in a global search. The fixture decorator is easy to search
> for, as is 'pytest_funcarg__'. Such an ugly prefix is also far easier
> to google. Double underscore, not so much. The ugly prefix is also
> good for backwards compat.
> So, I don't really mind what happens as long as each fixture has at
> least one of fixture decorator/ugly prefix.
Well, ok. Pending further input, i made pytest accept pytest.fixture
decorated pytest_funcarg__ prefixed functions, see
I am a bit unhappy because apart from the pylint warning it's also a
real issue for beginners to write something like this::
assert somename == 42
The "somename" is accessible (as a global) but is a function object.
The resulting error message is irritating if you are not proficient in python.
To prevent this irritation we would need to recommend a different
default way of declaring the fixture and neither pytest_funcarg__NAME nor
__NAME sound like we would like to suggest this as the main way in the docs.
Then again, my general recommendation is to put fixture functions into
conftest.py files and you then get a clean "NameError" in a test module
for the above example. The docs use the "everything contained in test module"
method, though, to make it easier to present getting-started examples.
Maybe it makes sense to mention this recommended conftest/test module
split earlier on.
More information about the Pytest-dev