diff --git a/README.rst b/README.rst index 2c0b8a0a1de7b12c48e19e85c0c27efcb91ddba5..b12866454c559d28faade7f53c28e96f58ab1f9d 100644 --- a/README.rst +++ b/README.rst @@ -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/ diff --git a/pytest_django_testing_postgresql.py b/pytest_django_testing_postgresql.py index c6ed64e8c3d8ed040c6d82b29e21a8d23df6b400..5f5e0d0707682272952e6c06d787234fff2c93c5 100644 --- a/pytest_django_testing_postgresql.py +++ b/pytest_django_testing_postgresql.py @@ -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() diff --git a/setup.py b/setup.py index eb7022ae66360e799a52c2927c6fbad41b00413b..660f6bd8575fd3d762ce6d0e551f4845d5dc7fe4 100644 --- a/setup.py +++ b/setup.py @@ -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',