Multiple copies of a pytest fixture
My approach would probably to create a fixture which can generate your objects:
@pytest.fixture
def thing(request, db):
class ThingFactory(object):
def get(self):
thing = MyModel.objects.create()
request.addfinalizer(thing.delete)
return thing
return ThingFactory()
def test_thing(thing):
thing1 = thing.get()
thing2 = thing.get()
Obviously you can make .get()
take an argument etc.
(PS: Also note there's no need for the lambda in the finalizer)