From b31e0beca097e9309b85f28ba997b4250ef72f1e Mon Sep 17 00:00:00 2001 From: Agate Berriot Date: Wed, 3 Aug 2022 14:59:12 +0200 Subject: [PATCH 2/2] Speed up authentic provisionning tests --- tests_authentic/conftest.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests_authentic/conftest.py b/tests_authentic/conftest.py index e2df497..23410c4 100644 --- a/tests_authentic/conftest.py +++ b/tests_authentic/conftest.py @@ -1,7 +1,9 @@ import json import os +import django.db.utils import pytest +from django.core.management import call_command from django.db import connection, transaction from django_webtest import DjangoTestApp, WebTestMixin from tenant_schemas.postgresql_backend.base import FakeTenant @@ -74,18 +76,28 @@ def tenant_factory(transactional_db, tenant_base, settings): schema_name = name.replace('-', '_').replace('.', '_') t = Tenant(domain_url=name, schema_name=schema_name) with transaction.atomic(): - t.create_schema() + t.create_schema(check_if_exists=True) + connection.set_schema_to_public() tenants.append(t) return t try: + yield factory finally: # cleanup all created tenants connection.set_schema_to_public() - with tenant_context(FakeTenant('public')): - for tenant in tenants: - tenant.delete(force_drop=True) + for tenant in tenants: + with tenant_context(tenant): + call_command( + "flush", + verbosity=0, + interactive=False, + database='default', + reset_sequences=False, + allow_cascade=True, + inhibit_post_migrate=False, + ) @pytest.fixture -- 2.36.1