Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added --pg-env option for passing environment to the PostgreSQL container #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pytest_postgres/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def pytest_addoption(parser):
help='Specify PostgreSQL server user password')
parser.addoption('--pg-database', action='store', default='postgres',
help='Specify test database name')
parser.addoption('--pg-env', action='append', default=[],
help='Specify environment values to pass to database container. '
'This option my be specified multiple times.')


@pytest.fixture(scope='session')
Expand All @@ -48,7 +51,7 @@ def check_connection(params):
pytest.fail('Could not connect to PostgreSQL server')


def create_container(docker, image, name, ports, network=None):
def create_container(docker, image, name, ports, network=None, env=None):
container = None

if name:
Expand All @@ -63,7 +66,8 @@ def create_container(docker, image, name, ports, network=None):
except APIError:
pass

container_params = {'image': image, 'name': name, 'detach': True}
container_params = {'image': image, 'name': name, 'detach': True,
'environment': env}

if network:
container_params['network'] = network
Expand All @@ -90,6 +94,7 @@ def pg_server(docker, request):
pg_image = request.config.getoption('--pg-image')
pg_reuse = request.config.getoption('--pg-reuse')
pg_network = request.config.getoption('--pg-network')
pg_env = request.config.getoption('--pg-env')

network = None
container = None
Expand All @@ -100,7 +105,9 @@ def pg_server(docker, request):

container = create_container(docker, pg_image, pg_name,
ports={'5432/tcp': None},
network=pg_network)
network=pg_network,
env=pg_env,
)
container.start()
container.reload()

Expand Down