Skip to content

Commit 0d0c72f

Browse files
committed
Make @pytest.mark.django_db markers more granular
1 parent 0ab23cc commit 0d0c72f

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

tests/test_baker.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ def test_multiple_inheritance_creation(self):
140140
).exists()
141141

142142

143-
@pytest.mark.django_db
144143
class TestsBakerRepeatedCreatesSimpleModel(TestCase):
144+
@pytest.mark.django_db
145145
def test_make_should_create_objects_respecting_quantity_parameter(self):
146146
with self.assertNumQueries(5):
147147
baker.make(models.Person, _quantity=5)
@@ -151,6 +151,7 @@ def test_make_should_create_objects_respecting_quantity_parameter(self):
151151
people = baker.make(models.Person, _quantity=5, name="George Washington")
152152
assert all(p.name == "George Washington" for p in people)
153153

154+
@pytest.mark.django_db
154155
def test_make_quantity_respecting_bulk_create_parameter(self):
155156
query_count = 1
156157
with self.assertNumQueries(query_count):
@@ -176,6 +177,7 @@ def test_make_quantity_respecting_bulk_create_parameter(self):
176177
)
177178
assert models.NonStandardManager.manager.count() == 3
178179

180+
@pytest.mark.django_db
179181
def test_make_raises_correct_exception_if_invalid_quantity(self):
180182
with pytest.raises(InvalidQuantityException):
181183
baker.make(_model=models.Person, _quantity="hi")
@@ -200,6 +202,7 @@ def test_prepare_raises_correct_exception_if_invalid_quantity(self):
200202
with pytest.raises(InvalidQuantityException):
201203
baker.prepare(_model=models.Person, _quantity=0)
202204

205+
@pytest.mark.django_db
203206
def test_accepts_generators_with_quantity(self):
204207
baker.make(
205208
models.Person,
@@ -220,6 +223,7 @@ def test_accepts_generators_with_quantity(self):
220223
assert p5.name == "b"
221224
assert p5.id_document == "d5"
222225

226+
@pytest.mark.django_db
223227
def test_accepts_generators_with_quantity_for_unique_fields(self):
224228
baker.make(
225229
models.DummyUniqueIntegerFieldModel,
@@ -237,6 +241,7 @@ def test_accepts_generators_with_quantity_for_unique_fields(self):
237241
not apps.is_installed("django.contrib.auth"),
238242
reason="Django auth app is not installed",
239243
)
244+
@pytest.mark.django_db
240245
def test_generators_work_with_user_model(self):
241246
from django.contrib.auth import get_user_model
242247

@@ -730,13 +735,14 @@ def test_nullable_many_to_many_is_not_created_if_not_flagged_and_fill_optional(
730735
assert classroom.students.count() == 0
731736

732737

733-
@pytest.mark.django_db
734738
class TestSkipBlanksTestCase:
739+
@pytest.mark.django_db
735740
def test_skip_blank(self):
736741
dummy = baker.make(models.DummyBlankFieldsModel)
737742
assert dummy.blank_char_field == ""
738743
assert dummy.blank_text_field == ""
739744

745+
@pytest.mark.django_db
740746
def test_skip_blank_with_argument(self):
741747
dummy = baker.make(models.DummyBlankFieldsModel, _fill_optional=False)
742748
assert dummy.blank_char_field == ""
@@ -753,8 +759,8 @@ def test_skip_blank_when_preparing_with_argument(self):
753759
assert dummy.blank_text_field == ""
754760

755761

756-
@pytest.mark.django_db
757762
class TestFillBlanksTestCase:
763+
@pytest.mark.django_db
758764
def test_fill_field_optional(self):
759765
dummy = baker.make(
760766
models.DummyBlankFieldsModel, _fill_optional=["blank_char_field"]
@@ -767,6 +773,7 @@ def test_fill_field_optional_when_preparing(self):
767773
)
768774
assert len(dummy.blank_char_field) == 50
769775

776+
@pytest.mark.django_db
770777
def test_fill_wrong_field(self):
771778
with pytest.raises(AttributeError) as exc_info:
772779
baker.make(
@@ -777,17 +784,20 @@ def test_fill_wrong_field(self):
777784
msg = "_fill_optional field(s) ['wrong'] are not related to model DummyBlankFieldsModel"
778785
assert msg in str(exc_info.value)
779786

787+
@pytest.mark.django_db
780788
def test_fill_wrong_fields_with_parent(self):
781789
with pytest.raises(AttributeError):
782790
baker.make(models.SubclassOfAbstract, _fill_optional=["name", "wrong"])
783791

792+
@pytest.mark.django_db
784793
def test_fill_many_optional(self):
785794
dummy = baker.make(
786795
models.DummyBlankFieldsModel,
787796
_fill_optional=["blank_char_field", "blank_text_field"],
788797
)
789798
assert len(dummy.blank_text_field) == 300
790799

800+
@pytest.mark.django_db
791801
def test_fill_all_optional(self):
792802
dummy = baker.make(models.DummyBlankFieldsModel, _fill_optional=True)
793803
assert len(dummy.blank_char_field) == 50
@@ -798,15 +808,18 @@ def test_fill_all_optional_when_preparing(self):
798808
assert len(dummy.blank_char_field) == 50
799809
assert len(dummy.blank_text_field) == 300
800810

811+
@pytest.mark.django_db
801812
def test_fill_optional_with_integer(self):
802813
with pytest.raises(TypeError):
803814
baker.make(models.DummyBlankFieldsModel, _fill_optional=1)
804815

816+
@pytest.mark.django_db
805817
def test_fill_optional_with_default(self):
806818
dummy = baker.make(models.DummyDefaultFieldsModel, _fill_optional=True)
807819
assert dummy.default_callable_int_field == 12
808820
assert isinstance(dummy.default_callable_datetime_field, datetime.datetime)
809821

822+
@pytest.mark.django_db
810823
def test_fill_optional_with_default_unknown_class(self):
811824
dummy = baker.make(models.DummyDefaultFieldsModel, _fill_optional=True)
812825
assert dummy.default_unknown_class_field == 42

0 commit comments

Comments
 (0)