From: Frédéric Perrin Date: Thu, 3 Nov 2016 19:06:04 +0000 (+0000) Subject: Start using pytest X-Git-Url: http://gitweb.fperrin.net/?p=djsite.git;a=commitdiff_plain;h=7d4d3d9380deb5d784cf52f9f3f136a551e5c522 Start using pytest --- diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..8cab58e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,2 @@ +[pytest] +DJANGO_SETTINGS_MODULE=djsite.settings diff --git a/quotes/test_quotes.py b/quotes/test_quotes.py index 36dcc1d..250ff30 100644 --- a/quotes/test_quotes.py +++ b/quotes/test_quotes.py @@ -1,23 +1,27 @@ from django.test import TestCase, Client # Create your tests here. +import pytest + from .models import QuoteTag, Author, Work, Quote import re import lxml.etree -class QuoteTest(TestCase): - def setUp(self): +class Test_QuoteTest(): + @pytest.fixture(scope='function') + def q1(self, db): a1 = Author.objects.create(name="JFK") w1 = Work.objects.create(name="Berlin speech", author=a1) q1 = Quote.objects.create(text="

Ich bin...

", work=w1) - self.q1 = q1 + return q1 - def test_one(self): + @pytest.mark.django_db + def test_one(self, q1): q = Quote.objects.filter(text__startswith="

Ich") - self.assertEqual(q.count(), 1) + assert q.count() == 1 q = q[0] - self.assertEqual(q, self.q1) - self.assertEqual(q.work.author.name, "JFK") + assert q == q1 + assert q.work.author.name == 'JFK' class ViewsTest(TestCase): def getPage(self, url, exp_status=200):