I'm using Django and Python 3.7. I would like to create and run some unit tests. Per the Django documentation, I created this file ...
ls ./mainpage/tests/test_models.py
But when I run my tests using the command below, it says zero tests were executed ...
(venv) localhost:mainpage_project davea$ cd /Users/davea/Documents/workspace/mainpage_project; source ./venv/bin/activate; python manage.py test
Creating test database for alias 'default'...
/Users/davea/Documents/workspace/mainpage_project/venv/lib/python3.7/site-packages/django/db/models/fields/__init__.py:1421: RuntimeWarning: DateTimeField Article.main_page_first_appeared_date received a naive datetime (2019-01-29 22:43:53.575128) while time zone support is active.
RuntimeWarning)
System check identified no issues (0 silenced).
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Destroying test database for alias 'default'...
Below are the contents of my file. What am I missing? Where should I put my tests or how should they be named so that they get executed?
from django.test import TestCase
from mainpage.models import ArticleStat, Article
class TestModels(unittest.TestCase):
# Test saving an article stat that hasn't previously
# existed
def test_add_articlestat(self):
id = 1
article = Article.objects.filter(id=id)
self.assertTrue(article, "A pre-condition of this test is that an article exist with id=" + str(id))
articlestat = ArticleStat(article=article,elapsed_time_in_seconds=250,votes=25,comments=15)
articlestat.save()
article_stat = ArticleStat.objects.get(article=article)
self.assertTrue(article_stat, "Failed to svae article stat properly.")
Aucun commentaire:
Enregistrer un commentaire