Skip to content

Commit b7fdb40

Browse files
committed
Convert test_models to pytest
1 parent b6898be commit b7fdb40

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lists/tests/test_models.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
from django.test import TestCase
21
from lists.models import List, Item
32
from django.core.exceptions import ValidationError
3+
import pytest
44

5+
pytestmark = pytest.mark.django_db
56

6-
class ItemModelTest(TestCase):
7+
8+
class TestItemModel:
79
def test_default_text(self):
810
item = Item()
9-
self.assertEqual(item.text, '')
11+
assert '' == item.text
1012

1113
def test_item_is_related_to_list(self):
1214
list_ = List.objects.create()
1315
item = Item()
1416
item.list = list_
1517
item.save()
16-
self.assertIn(item, list_.item_set.all())
18+
assert item in list_.item_set.all()
1719

1820
def test_cannot_save_empty_list_items(self):
1921
list_ = List.objects.create()
2022
item = Item(list=list_, text='')
21-
with self.assertRaises(ValidationError):
23+
with pytest.raises(ValidationError):
2224
item.save()
2325
item.full_clean()
2426

2527
def test_duplicate_items_are_invalid(self):
2628
list_ = List.objects.create()
2729
Item.objects.create(list=list_, text='bla')
28-
with self.assertRaises(ValidationError):
30+
with pytest.raises(ValidationError):
2931
item = Item(list=list_, text='bla')
3032
item.full_clean()
3133

@@ -41,18 +43,15 @@ def test_list_ordering(self):
4143
item1 = Item.objects.create(list=list1, text='i1')
4244
item2 = Item.objects.create(list=list1, text='item 2')
4345
item3 = Item.objects.create(list=list1, text='3')
44-
self.assertEqual(
45-
list(Item.objects.all()),
46-
[item1, item2, item3]
47-
)
46+
assert list(Item.objects.all()) == [item1, item2, item3]
4847

4948
def test_string_representation(self):
5049
item = Item(text='some text')
51-
self.assertEqual(str(item), 'some text')
50+
assert 'some text' == str(item)
5251

5352

54-
class ListModelTest(TestCase):
53+
class TestListModel:
5554

5655
def test_get_absolute_url(self):
5756
list_ = List.objects.create()
58-
self.assertEqual(list_.get_absolute_url(), '/lists/%d/' % list_.id)
57+
assert '/lists/%d/' % list_.id == list_.get_absolute_url()

0 commit comments

Comments
 (0)