On Sun, Jul 7, 2013 at 7:22 PM, Larry Martell <larry.mart...@gmail.com> wrote: > Just getting started with django unit testing. I created a very simple > test, just to see how things work. Here is my test: > > from django.test import TestCase > > fixtures = ['auth_user', 'auth_permission', 'data_cst'] > > class MeasDataTest(TestCase): > def test_MeasDate(self): > # login > response = self.client.post('/accounts/login//', {'username': > 'admin', 'password': 'xxxxx'}) > self.assertEqual(response.status_code, 200) > > > I ran 'python manage.py test' and got this output: > > Creating test database for alias 'default'... > ....F............................................................................E.............................................................................................................................................................................................Starting > batch of 1 tasks > MockRunnerKWArgs @ 2013-07-07 18:49:43.663905 > {"value": 5} > Completed in 0.04 seconds > 0.0421 seconds per task on average > 1 tasks succeeded (100.0% success rate) > > Dispatched 1 tasks in 0.0916 seconds using 1 process. > Average time per task is 0.0916 seconds > .Starting batch of 1 tasks > MockRunnerB @ 2013-07-07 18:49:51.635251 > > Completed in 0.03 seconds > 0.0270 seconds per task on average > 1 tasks succeeded (100.0% success rate) > Remaining tasks: 1 > > Starting batch of 1 tasks > MockRunnerC @ 2013-07-07 18:49:51.655887 > > Completed in 0.02 seconds > 0.0200 seconds per task on average > 1 tasks succeeded (100.0% success rate) > > Dispatched 2 tasks in 0.0486 seconds using 1 process. > Average time per task is 0.0243 seconds > .Starting batch of 1 tasks > MockRunnerA @ 2013-07-07 18:49:59.659529 > > Completed in 0.03 seconds > 0.0340 seconds per task on average > 1 tasks succeeded (100.0% success rate) > > Dispatched 1 tasks in 0.0360 seconds using 1 process. > Average time per task is 0.0360 seconds > .Dispatched 0 tasks in 0.0017 seconds using 1 process. > ....s....................................................................... > ====================================================================== > ERROR: test_site_profile_not_available > (django.contrib.auth.tests.models.ProfileTestCase) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File > "/Library/Python/2.7/site-packages/django/contrib/auth/tests/models.py", > line 29, in test_site_profile_not_available > del settings.AUTH_PROFILE_MODULE > File "/Library/Python/2.7/site-packages/django/utils/functional.py", > line 215, in __delattr__ > delattr(self._wrapped, name) > AttributeError: AUTH_PROFILE_MODULE > > ====================================================================== > FAIL: test_message_attrs > (django.contrib.auth.tests.context_processors.AuthContextProcessorTests) > ---------------------------------------------------------------------- > Traceback (most recent call last): > File > "/Library/Python/2.7/site-packages/django/contrib/auth/tests/context_processors.py", > line 58, in test_message_attrs > self.assertContains(response, "Message 1") > File "/Library/Python/2.7/site-packages/django/test/testcases.py", > line 637, in assertContains > msg_prefix + "Couldn't find '%s' in response" % text) > AssertionError: Couldn't find 'Message 1' in response > > ---------------------------------------------------------------------- > Ran 350 tests in 2354.881s > > FAILED (failures=1, errors=1, skipped=1) > Destroying test database for alias 'default'... > > But it never ran my tests. > > Questions:
I've figured out some of this myself. > > -What are the lines with the dots and F, E, and s? It appears each dot is a passed test and the F, E, and s are Failed, Error, and skipped. Is that is in the docs anywhere? > -What are the 350 tests it ran? The tests it's running appear to be the django tests from the contrib dirs that are in my INSTALLED_APPS (auth, contenttypes, sessions, sites, admin, and staticfiles). Why does it only print info on a few tests if it's running 350? Why is there 1 failure, 1 error and 1 skipped? Shouldn't all the contrib tests pass? > -Why didn't it run my test? Putting that aside for now, I specified my test on the command line: $ python manage.py test cdsem.MeasDataTest ValueError: Test label 'cdsem.MeasDataTest' does not refer to a test MeasDataTest is declared as: class MeasDataTest(TestCase): Why do I get "does not refer to a test"? Then I tried: $ python manage.py test cdsem Failed to install custom SQL for cdsem.Tool model: (1054, "Unknown column 'category' in 'field list'") Here is the def for the tool and category models: class Category(models.Model): class Meta: db_table = 'data_category' verbose_name_plural = "Categories" name = models.CharField(max_length=20, unique=True, db_index=True) event_path = models.CharField(max_length=512, null=True) data_path = models.CharField(max_length=512, null=True) file_spec = models.CharField(max_length=128, null=True) def __str__(self): return self.name class Tool(models.Model): class Meta: db_table = 'data_tool' name = models.CharField(max_length=10, unique=True) category = models.ForeignKey(Category) description = models.TextField(blank=True) ip = models.CharField(max_length=15, null=True) user = models.CharField(max_length=20, null=True) password = models.CharField(max_length=20, null=True) def __str__(self): return self.name These tables exist in db and are used by my app. Why does it get that error when I run the tests? -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. For more options, visit https://groups.google.com/groups/opt_out.