When you use the @pytest.mark.usefixtures marker, you still need to provide a similar input argument if you want this device to be introduced into your test function.
As described in py.test docs for fixtures :
The name of the binding function can be specified later to call it before starting the tests ... Test functions can directly use the device names as input arguments, in which case the fixture instance returned from the device function will be entered.
Therefore, just using the @pytest.mark.usefixtures decorator will only call the function. Providing an input argument will give you the result of this function.
You really need to use @pytest.mark.usefixtures when you want to use the tool but don't want it to be an input argument to your test. As described in py.test docs .
The reason you get an exception talking about user_setup as a function is because inside your function test_user name user_setup actually refers to the function defined earlier in the file. To make your code work as you expect, you will need to add an argument to the test_user function:
@pytest.mark.usefixtures('user_setup') class TestThings: def test_user(self, user_setup): assert user_setup['name'] == 'chad'
Now, from the point of view of the test_user function, the name user_setup will refer to the function argument, which will be the returned device value entered by py.test.
But actually you just don't need to use the @pytest.mark.usefixtures decorator at all.
source share