Skip to content

Commit

Permalink
Parametrized the tests with env var
Browse files Browse the repository at this point in the history
  • Loading branch information
fizyk committed Mar 17, 2021
1 parent ff39586 commit fabdd17
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
python-version: [3.7, 3.8, 3.9, pypy3]
postgres-version: [9.5, 9.6, 10, 11, 12, 12]
postgres-version: [9.5, 9.6, 10, 11, 12, 13]
env:
OS: ubuntu-latest
PYTHON: ${{ matrix.python-version }}
Expand Down
10 changes: 3 additions & 7 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pytest_postgresql import factories

pytest_plugins = ['pytester']
POSTGRESQL_VERSION = os.environ.get("POSTGRES", "13")


def find_pg_ctl(path: str) -> Path:
Expand Down Expand Up @@ -33,15 +34,10 @@ def create_version(ver: str) -> Path:
TEST_SQL_DIR = os.path.dirname(os.path.abspath(__file__)) + '/test_sql/'

# pylint:disable=invalid-name
postgresql95 = factories.postgresql_proc(create_version(ver='9.5'), port=None)
postgresql96 = factories.postgresql_proc(create_version(ver='9.6'), port=None)
postgresql10 = factories.postgresql_proc(create_version(ver='10'), port=None)
postgresql11 = factories.postgresql_proc(create_version(ver='11'), port=None)
postgresql12 = factories.postgresql_proc(create_version(ver='12'), port=None)
postgresql13 = factories.postgresql_proc(create_version(ver='13'), port=None)
postgresql_proc_version = factories.postgresql_proc(create_version(ver=POSTGRESQL_VERSION), port=None)
postgresql_version = factories.postgresql('postgresql_proc_version')

postgresql_proc2 = factories.postgresql_proc(port=9876)
postgres10 = factories.postgresql('postgresql10')
postgresql2 = factories.postgresql('postgresql_proc2', db_name='test-db')
postgresql_load_1 = factories.postgresql('postgresql_proc2', db_name='test-db',
load=[TEST_SQL_DIR + 'test.sql', ])
Expand Down
27 changes: 10 additions & 17 deletions tests/test_noopexecutor.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,19 @@
from pytest_postgresql.factories import NoopExecutor


def test_nooproc_version_9(postgresql_proc):
"""Test the way postgresql version is being read for versions < 10."""
postgresql_nooproc = NoopExecutor(
postgresql_proc.host,
postgresql_proc.port,
postgresql_proc.user,
postgresql_proc.options
)
assert postgresql_proc.version == postgresql_nooproc.version

def test_nooproc_version(postgresql_proc_version):
"""
Test the way postgresql version is being read.
def test_nooproc_version_post_10(postgresql11):
"""Test the way postgresql version is being read for versions >= 10."""
Version behaves differently for postgresql >= 10 and differently for older ones
"""
postgresql_nooproc = NoopExecutor(
postgresql11.host,
postgresql11.port,
postgresql11.user,
postgresql11.options
postgresql_proc_version.host,
postgresql_proc_version.port,
postgresql_proc_version.user,
postgresql_proc_version.options
)
assert postgresql11.version == postgresql_nooproc.version
assert postgresql_proc_version.version == postgresql_nooproc.version


def test_nooproc_cached_version(postgresql_proc):
Expand Down
17 changes: 4 additions & 13 deletions tests/test_postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@
SELECT_Q = "SELECT * FROM test;"


@pytest.mark.parametrize('postgres', (
'postgresql95',
'postgresql96',
'postgresql10',
'postgresql11',
'postgresql12',
'postgresql13'
))
def test_postgresql_proc(request, postgres):
def test_postgresql_proc(postgresql_proc_version):
"""Test different postgresql versions."""
postgresql_proc = request.getfixturevalue(postgres)
assert postgresql_proc.running() is True
assert postgresql_proc_version.running() is True


def test_main_postgres(postgresql):
Expand Down Expand Up @@ -67,13 +58,13 @@ def test_rand_postgres_port(postgresql_rand):

@pytest.mark.parametrize('_', range(2))
def test_postgres_terminate_connection(
postgres10, _):
postgresql_version, _):
"""
Test that connections are terminated between tests.
And check that only one exists at a time.
"""
cur = postgres10.cursor()
cur = postgresql_version.cursor()
cur.execute(
'SELECT * FROM pg_stat_activity '
'WHERE backend_type = \'client backend\';'
Expand Down

0 comments on commit fabdd17

Please sign in to comment.