Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3428164
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:55:33+00:00 2026-05-18T06:55:33+00:00

From Django docs : …the database is not refreshed between doctests, so if your

  • 0

From Django docs:

…the database is not refreshed between doctests, so if your doctest requires a certain state you should consider flushing the database or loading a fixture.

Quite frankly, 90% of my testing is currently done in doctests. A colleague of mine thought that was peculiar. In all honesty, I do very little testing so I do not pretend to be a master of that field.

Does anyone have a rule of thumb they use when deciding how to test?

Non-SO answer

A colleague of mine suggested to test model functions and constraints as doctests and views via unit tests. How does that sound for a rule of thumb?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:55:34+00:00Added an answer on May 18, 2026 at 6:55 am

    As your project grows, you’ll find that unittests are far better for testing your code.

    The Django project itself is in the process of converting all doctests to unittests (we’ll be done by the 1.3 release). The reason we’re doing this is that prior to this conversion, the order of execution in the test suite would sometimes cause hard to reproduce errors. Sometimes a bit of code would accidentally depend on previously run doctest code. Additionally, switching to unittests has speed the overall test time up, since we can be more judicious about how and when we clear the database.

    The other advantage unittests have is that they are MUCH easier to maintain. Because the entire test case is self-contained, you either write another test case, or modify the small, targeted test function to suit.

    Doctests tend to work by evolution – you get an instance of your widget, add green fur, make sure the fur is green, add 4 legs, make sure you have 4 legs and green fur, add a thumb, make sure you have a thumb, 4 legs, and green fur, etc… This means that if you want to add a test right after the green fur stage, you have to modify the expected results for every other test case following.

    You don’t want to do all this rewriting, so you add your new test at the end. Then you add another, and then after a while your tests are so hopelessly jumbled you can’t figure out whether or not a specific feature is even tested! With unittests, since each test embodies a specific, concrete and limited idea, it’s much easier to re-order the tests logically, and to add a new test that doesn’t depend on all the previous ones. Additionally, if you change the way add_green_fur() works, you don’t have to modify dozens of test case results.

    The other advantage is that unittests (when written well) tell you precisely where your code failed. Failed: MyWidget.tests.test_green_fur() is a lot easier to debug than “widget test failed at line 384”, which is often dozens to hundreds of lines away from the actual point of failure.

    In general, unittests are the better way to test.

    Edit:

    In response to your colleague’s idea, I respectfully suggest that he hasn’t worked on a large project with many doctests. Doctests in models are just as bad as in views. They have precisely the same problems (though if anything, doctests are worse in models because flush is very expensive and absolutely necessary for thorough doctesting). Don’t underestimate the cost of the time taken by running tests.

    Also, don’t mix your test types unless you have a VERY good reason to do so. If you do, you’ll very quickly find yourself doubling up tests, or assuming that a function is tested in whichever test suite you don’t happen to be looking at.

    Doctests are often touted as “providing documentation” for how your code is supposed to work. That’s nice, but it’s not a substitute for writing readable code with good legible inline comments. If you want further documentation, write it out separately!

    You can’t write good tests that also function as good documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application where I will be accessing the database from django
I'm trying to set up the simple syndication example from the Django docs, in
I have an unusual problem. Let's consider such models (taken from django docs): class
I'm trying to implement signals from Django ( http://docs.djangoproject.com/en/dev/topics/signals/ ), or its concept in
I'm customizing django comments. According to the docs you'll need to add your customized
Im looking to learn more about your testing flows with Django. Background information http://docs.djangoproject.com/en/dev/topics/testing/
From django documentation: js_info_dict = { 'packages': ('your.app.package',), } urlpatterns = patterns('', (r'^jsi18n/$', 'django.views.i18n.javascript_catalog',
Given: from django.db import models class Food(models.Model): Food, by name. name = models.CharField(max_length=25) class
In Django, given excerpts from an application animals likeso: A animals/models.py with: from django.db
Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.