Why is test case failing in Django when it returns True in Python intrepreter? -


when run code in python interpreter, returns true:

>>> movies.models import movie >>> movie_list = movie.objects.all() >>> bool(movie_list) true 

when run test case, python3 manage.py test movies, fails:

from django.test import testcase .models import movie  class questionmethodtests(testcase):      def test_movie_list_empty(self):         movie_list = movie.objects.all()         self.assertequal(bool(movie_list), true) 

what missing? shouldn't test pass?

i see. mean test cases test code can't use of actual database content in tests?

by default no, , don't want mess actual db anyway, there usual way provide initial objects tests (the actual source can differ, e.g. loading file)

from django.test import testcase .models import movie  class questionmethodtests(testcase):      def setup(self):         # can create movie objects here         movie.objects.create(title='forest gump', ...)      def test_movie_list_empty(self):         movie_list = movie.objects.all()         self.assertequal(bool(movie_list), true) 

the testcase class contains setuptestdata method if fancy that, https://docs.djangoproject.com/en/1.8/topics/testing/tools/#django.test.testcase.setuptestdata

ps: test_movie_list_empty name sounds weird, cause seems test movie list not empty


Comments

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -