Skip to content
Snippets Groups Projects
Verified Commit 8d7730b7 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Allow database configuration

parent 30887fe3
No related branches found
No related tags found
No related merge requests found
......@@ -24,11 +24,10 @@ auto-discovers it).
The plugin re-uses the configuration used by `pytest-django`_.
Limitations
-----------
Right now, this plugin can only reconfigure the `default` database.
By default, only the ``default`` database is setup. You can modify this
by setting ``PYTEST_SETUP_DATABASES`` to a list of database aliases in
your ``settings`` module. The list can contain strings, or tuples if you
want some aliases to share the same database backend.
.. _testing.postgresql: https://pypi.org/project/testing.postgresql/
.. _pytest-django: https://pypi.org/project/pytest-django/
......@@ -5,13 +5,23 @@ from django.conf import settings
import pytest
from testing.postgresql import Postgresql
_POSTGRESQL = Postgresql()
_POSTGRESQLS = []
@pytest.hookimpl(tryfirst=True)
def pytest_load_initial_conftests(early_config, parser, args):
os.environ['DJANGO_SETTINGS_MODULE'] = early_config.getini('DJANGO_SETTINGS_MODULE')
settings.DATABASES['default'] = parse(_POSTGRESQL.url())
db_sets = getattr(settings, "PYTEST_SETUP_DATABASES", [("default",)])
for db_set in db_sets:
postgresql = Postgresql()
if isinstance(db_set, str):
db_set = [db_set]
for db in db_set:
settings.DATABASES[db] = parse(postgresql.url())
_POSTGRESQLS.append(postgresql)
def pytest_unconfigure(config):
_POSTGRESQL.stop()
for postgresql in _POSTGRESQLS:
postgresql.stop()
......@@ -8,7 +8,7 @@ with open(path.join(this_directory, 'README.rst'), encoding='utf-8') as f:
setup(
name="pytest-django-testing-postgresql",
version='0.1.post0',
version='0.2',
description='Use a temporary PostgreSQL database with pytest-django',
long_description=long_description,
author='Dominik George',
......@@ -16,7 +16,7 @@ setup(
url='https://edugit.org/AlekSIS/libs/pytest-django-testing-postgresql',
classifiers=[
'Development Status :: 3 - Alpha',
'Development Status :: 4 - Beta',
'Framework :: Django',
'Framework :: Pytest',
'Intended Audience :: Developers',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment