Django: Параметризованное расширение с только что созданным объектом модели не работает

Я пытаюсь протестировать некоторый код django.

Я хочу использовать parameterized.expand для предоставления вновь созданных Boat объектов модели методу с именем test_method

Я создаю эти объекты модели Boat в методе setUp тестового класса.

Мое (ошибочное) понимание следующее:

  1. MyTestClass.setUp is run and it creates the Boat objects into the test database
  2. test_method is run for each group of variables in the parameterized decorator. Note, the parameterized decorator references the newly created Boat objects.

Что происходит на самом деле:

  1. parameterized decorator is instantiated at build time, before setUp is run
  2. an error is thrown because there are no Boat objects (because setUp hasn'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?

Вернуться на верх