Django and postgresql testing schema
I ended up with writing a custom test runner to solve this problem (using django 1.9.x):
myapp/test/runner.py
from types import MethodTypefrom django.test.runner import DiscoverRunnerfrom django.db import connectionsdef prepare_database(self): self.connect() self.connection.cursor().execute(""" CREATE SCHEMA foobar_schema AUTHORIZATION your_user; GRANT ALL ON SCHEMA foobar_schema TO your_user; """)class PostgresSchemaTestRunner(DiscoverRunner): def setup_databases(self, **kwargs): for connection_name in connections: connection = connections[connection_name] connection.prepare_database = MethodType(prepare_database, connection) return super().setup_databases(**kwargs)
settings.py
TEST_RUNNER = 'myapp.test.runner.PostgresSchemaTestRunner'