tests: load schema2 fixture only one time (#38067)
Use special db fixture (using pytest-django primitives and transaction.atomic()) to initialize bijoe visualization only one time for all tests on the schema2 fixture. It improves tests run time.
This commit is contained in:
parent
833449e236
commit
7f4f373e89
|
@ -1,7 +1,7 @@
|
|||
import os
|
||||
import glob
|
||||
import json
|
||||
from contextlib import closing
|
||||
from contextlib import closing, contextmanager
|
||||
import subprocess
|
||||
import tempfile
|
||||
import shutil
|
||||
|
@ -13,7 +13,7 @@ import django_webtest
|
|||
import psycopg2
|
||||
|
||||
|
||||
from django.db import connection
|
||||
from django.db import transaction
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.management import call_command
|
||||
|
||||
|
@ -49,6 +49,7 @@ def admin(db):
|
|||
SCHEMA_PATHS = os.path.join(os.path.dirname(__file__), 'fixtures/')
|
||||
|
||||
|
||||
@contextmanager
|
||||
def load_schema_db(schema):
|
||||
import random
|
||||
|
||||
|
@ -107,8 +108,8 @@ def load_schema_db(schema):
|
|||
|
||||
@pytest.fixture(scope='module')
|
||||
def schema1_db():
|
||||
for x in load_schema_db('schema1'):
|
||||
yield x
|
||||
with load_schema_db('schema1') as d:
|
||||
yield d
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -121,13 +122,23 @@ def schema1(db, schema1_db, settings):
|
|||
|
||||
@pytest.fixture(scope='module')
|
||||
def schema2_db():
|
||||
for x in load_schema_db('schema2'):
|
||||
yield x
|
||||
with load_schema_db('schema2') as d:
|
||||
yield d
|
||||
|
||||
|
||||
@pytest.fixture(scope='module')
|
||||
def schema2_fixtures(schema2_db, django_db_setup, django_db_blocker):
|
||||
with django_db_blocker.unblock():
|
||||
with transaction.atomic():
|
||||
try:
|
||||
for json_fixture in schema2_db['fixtures']:
|
||||
call_command('loaddata', json_fixture)
|
||||
yield
|
||||
finally:
|
||||
transaction.set_rollback(True)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def schema2(db, schema2_db, settings):
|
||||
def schema2(schema2_db, schema2_fixtures, settings, django_db_blocker):
|
||||
settings.BIJOE_SCHEMAS = schema2_db['bijoe_schemas']
|
||||
for json_fixture in schema2_db['fixtures']:
|
||||
call_command('loaddata', json_fixture)
|
||||
return schema2_db
|
||||
yield schema2_db
|
||||
|
|
Loading…
Reference in New Issue