-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
27 lines (20 loc) · 967 Bytes
/
Copy pathconftest.py
File metadata and controls
27 lines (20 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""Pytest session setup.
Test DB and test role are pre-provisioned by scripts/server/instance.sh.
The test role owns the same-named test DB but has no CREATEDB — so we cannot let
pytest-django's default setup_databases run (it would try CREATE DATABASE).
Instead, swap the connection name to the test DB, drop and recreate the
public schema (the test role can do this because it owns the DB), and run
migrations from scratch each session.
"""
import pytest
@pytest.fixture(scope="session")
def django_db_setup(django_db_blocker):
from django.core.management import call_command
from django.db import connection
with django_db_blocker.unblock():
connection.settings_dict["NAME"] = connection.settings_dict["USER"]
connection.close()
with connection.cursor() as cursor:
cursor.execute("DROP SCHEMA public CASCADE")
cursor.execute("CREATE SCHEMA public")
call_command("migrate", "--no-input")