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 8081837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:51:56+00:00 2026-06-05T16:51:56+00:00

I have a large readonly Wordnet PostgreSQL database that I’d like to use from

  • 0

I have a large readonly Wordnet PostgreSQL database that I’d like to use from Django unittests. Specifically, I have an app, called “wordnet”, that wraps this Wordnet database. Unfortunately, the default Django unittest framework uses an empty in-memory SQLite database for all apps.

How do I use my PostgreSQL database for only the wordnet app, and no other apps, within unittests?

I’m familiar with Django database routers, and I think they might be a solution. So I’ve created the following in my routers.py:

NEEDS_REAL_DB_APPS = (
    'wordnet',
    'auth',
    'contenttypes',
)
REAL_DB = 'default'

class UseRealDBRouter(object):

    def db_for_read(self, model, **hints):
        if model._meta.app_label in NEEDS_REAL_DB_APPS:
            return REAL_DB
        return None

    def db_for_write(self, model, **hints):
        if model._meta.app_label in NEEDS_REAL_DB_APPS:
            return REAL_DB
        return None

    def allow_relation(self, obj1, obj2, **hints):
        if obj1._meta.app_label in NEEDS_REAL_DB_APPS and obj2._meta.app_label in NEEDS_REAL_DB_APPS:
            return True
        return None

    def allow_syncdb(self, db, model):
        if db == REAL_DB:
            return model._meta.app_label in NEEDS_REAL_DB_APPS
        elif model._meta.app_label in NEEDS_REAL_DB_APPS:
            return False
        return None

And my tests.py looks like:

from django.test import TestCase
from wordnet import models as wn_models

class Tests(TestCase):

    def test_wordnet(self):
        q = wn_models.Word.objects.all()
        self.assertEqual(q.count(), 86547)

However, when I run my unittest (e.g. manage.py test myapp.Tests.test_wordnet), the check still fails, returning 0 for a count of all the words, indicating it’s still not using the “real” database. What am I doing wrong?

  • 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-06-05T16:51:59+00:00Added an answer on June 5, 2026 at 4:51 pm

    You should not use real database for testing.

    How about first dumping your production database: look here

    and then loading it in test fixtures: check this

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

Sidebar

Related Questions

I have a case here that I would like to have some opinions from
i have large numbers of text files and i am in problem that i
I have large images displayed in a grouped tableview. I would like the images
I have large database table, approximately 5GB, now I wan to getCurrentSnapshot of Database
I have large video files (~100GB) that are local on my machine. I have
We have a large read only secondary database file. We have several different copies
We have a large MyISAM table that is used to archive old data. This
I have a large amount of text data that I want to display in
I have a process that (at night) takes a large chunk of data in
In my page I have a read-only TextBox that contains a rather large amount

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.