You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to use pytest with django-tenants which uses PostgreSQL schemas to isolate clients. How do I configure pytest-django so that if I am using TenantTestCase which actually creates a test schema along with public starts to use both the schema's or set the database search path to 'search_path=test, public'.
It seems pytest is only using the public schema and thus fails to find out the test schema.
The models that I want to test gets created in test schema, isolated from public.
I read in the documentation that pytest-django doesn't play well with multiple databases. Is it true with multiple schema's as well which are in a single database?
The tests are running fine with manage.py test (Django inbuilt testing) and utilizing both the schemas.
Thanks.
The text was updated successfully, but these errors were encountered:
This is not pytest-django issue. I personally worked around this by making fixture that creates the tenant and activates it. A simple version would go something like this:
import pytest
from django_tenants.utils import tenant_context
@pytest.fixture
def tenant(db):
tenant = Tenant(schema_name="test")
tenant.save(verbosity=0)
tenant.domains.create(domain="tenant.test.com", read_only=True)
with tenant_context(tenant):
yield tenant
tenant.save()
Then you can create a test like this:
def test_create_user(tenant):
# Tenant is activated in this test.
pytest-django does not support using custom TestCases. You can always use the TenantTestCase itself as unittest test and pytest will pick it up as normal.
Uh oh!
There was an error while loading. Please reload this page.
Hi,
I am trying to use
pytest
withdjango-tenants
which usesPostgreSQL
schemas to isolate clients. How do I configurepytest-django
so that if I am usingTenantTestCase
which actually creates atest
schema along withpublic
starts to use both the schema's or set the database search path to 'search_path=test, public'.It seems pytest is only using the
public
schema and thus fails to find out thetest
schema.The models that I want to test gets created in
test
schema, isolated frompublic
.I read in the documentation that pytest-django doesn't play well with multiple databases. Is it true with multiple schema's as well which are in a single database?
The tests are running fine with
manage.py test
(Django inbuilt testing) and utilizing both the schemas.Thanks.
The text was updated successfully, but these errors were encountered: