Skip to content

Multiple application, multiple database - not able to access any DB other than default db #839

Closed
@praveenelan

Description

@praveenelan

Problem

I have a Django(1.8) project running 2 applications: App1, App2. Both of the applications run with their own databases: app1db and app2db, sharing the defaultdb for users and groups. I am trying to integrate pytest-django as part of the unit testing. This is where I am hitting with problem as Pytest do not support multiple databases.

My use case is I would be needing the unit tests only on app1 and I am pretty much sure I won't be needing it on app2. And I can mock my users and groups objects from defaultdb for this unit tests and I won't be needing access to defaultdb. But the problem is I always see the unit tests access the defaultdb and I don't see a way of making the app1db accessible from unit test cases. When I try to access any object form app1db, I get the following error:

E ProgrammingError: relation "app1_table" does not exist E LINE 1: INSERT INTO "app1_table" ("field1", "field2", "... E ^

Database Settings

{
'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'USER': 'postgres',
    'NAME': 'defaultdb',
    'PASSWORD': 'pass',
    'HOST': localhost,
},
'app1': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'app1db',
    'USER': 'postgres',
    'PASSWORD': 'pass',
    'HOST': localhost,
},
"app2": {
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'app2db',
    'USER': 'postgres',
    'PASSWORD': 'pass',
    'HOST': localhost,
},

How do I make my pytest just look for app1db ignoring all other DBs?

SO : https://stackoverflow.com/questions/61621853/pytest-django-multiple-application-multiple-database-not-able-to-access-any

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions