mercredi 11 mars 2015

PyTest fixture with session scope does not maintains continuity of db data


Vote count:

0




This test session works properly :



from myapp.models import MyModel
@pytest.fixture(scope='function')
def mymodel():
return G(MyModel)

@pytest.mark.django_db
def test_mymodel_one(mymodel):
assert MyModel.objects.count() > 0

@pytest.mark.django_db
def test_mymodel_two(mymodel):
assert MyModel.objects.count() > 0


and produces this output:



========= test session starts =========
tests/myapp/test_pp.py::test_mymodel_one PASSED
tests/myapp/test_pp.py::test_mymodel_two PASSED


but if I change the scope of my fixture to 'session', test two fails:



========= test session starts =========
tests/myapp/test_pp.py::test_mymodel_one PASSED
tests/myapp/test_pp.py::test_mymodel_two FAILED

========= FAILURES ==============
_________ test_mymodel_two ________
tests/myapp/test_pp.py:85: in test_mymodel_two
assert MyModel.objects.count() > 0
E assert 0 > 0


The object created is correctly returned from fixture (I can access his values) but it isn't stored no more. How can I use session scope and maintain the storage in my test db?



asked 18 secs ago







PyTest fixture with session scope does not maintains continuity of db data

Aucun commentaire:

Enregistrer un commentaire