Projet

Général

Profil

0001-tests-load-schema2-fixture-only-one-time-38067.patch

Benjamin Dauvergne, 03 décembre 2019 15:11

Télécharger (2,43 ko)

Voir les différences:

Subject: [PATCH 01/13] 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.
 tests/conftest.py | 31 +++++++++++++++++++++----------
 1 file changed, 21 insertions(+), 10 deletions(-)
tests/conftest.py
1 1
import os
2 2
import glob
3 3
import json
4
from contextlib import closing
4
from contextlib import closing, contextmanager
5 5
import subprocess
6 6
import tempfile
7 7
import shutil
......
13 13
import psycopg2
14 14

  
15 15

  
16
from django.db import connection
16
from django.db import transaction
17 17
from django.contrib.auth.models import User
18 18
from django.core.management import call_command
19 19

  
......
49 49
SCHEMA_PATHS = os.path.join(os.path.dirname(__file__), 'fixtures/')
50 50

  
51 51

  
52
@contextmanager
52 53
def load_schema_db(schema):
53 54
    import random
54 55

  
......
107 108

  
108 109
@pytest.fixture(scope='module')
109 110
def schema1_db():
110
    for x in load_schema_db('schema1'):
111
        yield x
111
    with load_schema_db('schema1') as d:
112
        yield d
112 113

  
113 114

  
114 115
@pytest.fixture
......
121 122

  
122 123
@pytest.fixture(scope='module')
123 124
def schema2_db():
124
    for x in load_schema_db('schema2'):
125
        yield x
125
    with load_schema_db('schema2') as d:
126
        yield d
127

  
128

  
129
@pytest.fixture(scope='module')
130
def schema2_fixtures(schema2_db, django_db_setup, django_db_blocker):
131
    with django_db_blocker.unblock():
132
        with transaction.atomic():
133
            try:
134
                for json_fixture in schema2_db['fixtures']:
135
                    call_command('loaddata', json_fixture)
136
                yield
137
            finally:
138
                transaction.set_rollback(True)
126 139

  
127 140

  
128 141
@pytest.fixture
129
def schema2(db, schema2_db, settings):
142
def schema2(schema2_db, schema2_fixtures, settings, django_db_blocker):
130 143
    settings.BIJOE_SCHEMAS = schema2_db['bijoe_schemas']
131
    for json_fixture in schema2_db['fixtures']:
132
        call_command('loaddata', json_fixture)
133
    return schema2_db
144
    yield schema2_db
134
-