For my web server, I have a login
fixture that create a user and returns the headers needed to send requests. For a certain test, I need two users. How can I use the same fixture twice in one function?
from test.fixtures import login
class TestGroups(object):
def test_get_own_only(self, login, login):
pass
I do it with
Dummy
class which will implement fixture functionality. Then just call it from your test. Provide clarify method name to better understand what is your test doing.I needed my tests to directly call a fixture to overwrite the current instanced result, so I wrote an abstraction layer that contains references to all of my fixtures:
Called with (get_session is another fixture):
An alternative is just to copy the fixture function. This is both simple and correctly handles parameterized fixtures, calling the test function with all combinations of parameters for both fixtures. This example code below raises 9 assertions:
I have done it like so:
The trick is to use mark.parametrize with the "indirect" switch, thus: