Note that there are some explanatory texts on larger screens.

plurals
  1. POdifference between django.test.TestCase vs unittest vs django.utils.unittest.TestCase
    text
    copied!<p>I am still using Django 1.2.1, and I think with the newer Django we don't <code>import unittest</code> and then do <code>unittest.TestCase</code>.</p> <p><strong>Illustration</strong></p> <pre><code>import unittest class TestThis(unittest.TestCase): from django.utils.unittest import TestCase class TestThis(TestCase): from django.test import TestCase class TestThis(TestCase): </code></pre> <p>According to <a href="http://pycon-2012-notes.readthedocs.org/en/latest/testing_and_django.html" rel="noreferrer">PyCon2011 talk</a>, the second one is <strong>slightly</strong> more efficient. </p> <p>Here is the <a href="https://docs.djangoproject.com/en/dev/topics/testing/#testcase" rel="noreferrer">diagram</a> showing the relations:</p> <p><img src="https://i.stack.imgur.com/YyqWD.png" alt="enter image description here"></p> <p>So <code>django.utils.unittest</code> and <code>django.test</code> inherit from either <code>unittest</code> or <code>unittest2</code>.</p> <p>I am not sure if the following is correct or not. Please help editing.</p> <pre><code> ________________________________________________________________ | Name | Django Version | Python Version | ----------------------------------------------------------------- | unittest | &gt;= 1.0 | &gt;= 2.6 | ----------------------------------------------------------------- | django.utils.unittest | &gt;= 1.3 | ?? | ----------------------------------------------------------------- | django.test | &gt;= 1.0 | &gt;= 2.6 | | - SimpleTestCase &gt;= 1.4 &gt;= 2.7 | | - LiveServerTestCase &gt;= 1.4 &gt;= 2.7 | ----------------------------------------------------------------- </code></pre> <p>In terms of efficiency, which one of the three is better? Many Django developers mock when they test, so sometimes database are not even necessary. Is there a way not creating tables when we run <code>manage.py test myapp.MyClass</code> ? For older version (prior to 1.3), which one is better? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload