Django: Параметризованное расширение с только что созданным объектом модели не работает
Я пытаюсь протестировать некоторый код django.
Я хочу использовать parameterized.expand для предоставления вновь созданных Boat объектов модели методу с именем test_method
Я создаю эти объекты модели Boat в методе setUp тестового класса.
Мое (ошибочное) понимание следующее:
MyTestClass.setUpis run and it creates theBoatobjects into the test databasetest_methodis run for each group of variables in theparameterizeddecorator. Note, the parameterized decorator references the newly createdBoatobjects.
Что происходит на самом деле:
parameterizeddecorator is instantiated at build time, beforesetUpis run- an error is thrown because there are no
Boatobjects (becausesetUphasn't run yet`)
Вот код:
from core.models import Boat
from parameterized import parameterized
class MyTestClass:
def setUp(self):
Boat.objects.create()
@parameterized.expand(
[
[[Boat.objects.all()], 1],
]
)
def test_method(self, list_of_boats, expected_number_of_boats]):
assert len(list_of_boats] == expected_number_of_boats
Я получаю ошибку
sqlite3.OperationalError: no such table: core_boat
Как использовать вновь созданные объекты модели с помощью parameterized.expand?