From 0359ba54bac6d48b44e64eeecbdb8e31de48ab49 Mon Sep 17 00:00:00 2001 From: Travis Shirk Date: Wed, 19 Feb 2020 09:38:11 -0700 Subject: [PATCH 1/2] Added `--pg-env` option for passingn environment to the PostgreSQL container. Recent postgres images require `POSTGRES_HOST_AUTH_METHOD=trust` to allow behavior matching prior versions. --- pytest_postgres/plugin.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pytest_postgres/plugin.py b/pytest_postgres/plugin.py index 1a39768..d1bc5c4 100644 --- a/pytest_postgres/plugin.py +++ b/pytest_postgres/plugin.py @@ -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') @@ -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: @@ -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 @@ -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 @@ -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() From eb7549811c1948414771ab731a2cd79395f145b2 Mon Sep 17 00:00:00 2001 From: Travis Shirk Date: Wed, 26 Feb 2020 15:57:04 -0700 Subject: [PATCH 2/2] Always set POSTGRES_HOST_AUTH_METHOD=trust when a value is not provided and add python3.8 to test matrix --- pytest_postgres/plugin.py | 14 ++++++++++++-- tox.ini | 3 ++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/pytest_postgres/plugin.py b/pytest_postgres/plugin.py index d1bc5c4..b9cff98 100644 --- a/pytest_postgres/plugin.py +++ b/pytest_postgres/plugin.py @@ -27,7 +27,8 @@ def pytest_addoption(parser): 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. ' + help='Specify environment values to pass to database ' + 'container. ' 'This option my be specified multiple times.') @@ -94,7 +95,16 @@ 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') + + # Convert list of env values to a dict. + pg_env = {} + for env in request.config.getoption('--pg-env'): + name, value = env.split("=", maxsplit=1) + pg_env[name] = value + + # Add POSTGRES_HOST_AUTH_METHOD=trust is needed. + if "POSTGRES_HOST_AUTH_METHOD" not in pg_env: + pg_env["POSTGRES_HOST_AUTH_METHOD"] = "trust" network = None container = None diff --git a/tox.ini b/tox.ini index f3b2690..ba0b489 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,12 @@ [tox] -envlist = lint,py35,py36,py37 +envlist = lint,py35,py36,py37,py38 [travis] python = 3.5: py35 3.6: py36 3.7: py37 + 3.8: py38 [testenv] extras = test