Pytest: misleading warning about _fillfuncargs when calling fillfixtures

Created on 29 Sep 2020  路  6Comments  路  Source: pytest-dev/pytest

This warning:
https://github.com/pytest-dev/pytest/blob/cd67c2a8cf6a2c690a5f77b50e3b61e01c5263be/src/_pytest/deprecated.py#L23-L26

...is raised from:

https://github.com/pytest-dev/pytest/blob/cd67c2a8cf6a2c690a5f77b50e3b61e01c5263be/src/_pytest/fixtures.py#L342-L344

...suggesting the former is wrong, and super confusing when you're trying to track down where a warning is coming from in a plugin.

Related: what is the public and approved way for pytest plugins to explicitly request fixtures now?

I do this dance currently, but I've always wished for something more pleasant:

https://github.com/cjw296/sybil/blob/734a5769af840e6bf03f84e4eea9f9ed2681c4bb/sybil/integration/pytest.py#L41-L75

easy docs

All 6 comments

suggesting the former is wrong

Can you explain what is wrong about it?

Related: what is the public and approved way for pytest plugins to explicitly request fixtures now?

(I'll try to answer that later)

What's wrong about it? The method is called fillfixtures, not _fillfuncargs, and the stacklevel=2 then makes it difficult to find out where the warning is coming from.

Hah got it. IIRC this was done because _pytest.fixtures.fillfixtures is under the _pytest namespace which is supposed to be ~private, and pytest._fillfuncargs is its public alias under the public pytest namespace (don't ask me why it has an underscore in its name), so the public name was used in the message.

It can't hurt to add _pytest.fixtures.fillfixtures to the message as well though. And fix the stacklevel if it's wrong.

Related: what is the public and approved way for pytest plugins to explicitly request fixtures now?

Since your code already uses a lot of internal details, you can replace fixtures.fillfixtures(self) with self._request._fillfixtures() which does the same. This is not public though. For something a little more public you can do the self.funcargs[argname] = self._request.getfixturevalue(argname) loop youself; getfixturevalue is public.

As for replacing the entire dance, short of reusing Function I don't think there's anything, but I'm not super familiar with this area.

How can I help here? what needs documentation?

@abhisht51 Looks like this has been picked up already via #7829.

Was this page helpful?
0 / 5 - 0 ratings