Skip to content

Commit

Permalink
separate sqlite and postgresql
Browse files Browse the repository at this point in the history
  • Loading branch information
RogerHYang committed Oct 5, 2024
1 parent eaab9f1 commit 4b8eec3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 19 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/python-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,19 @@ jobs:
strategy:
matrix:
py: [ 3.9, 3.12 ]
db: [ sqlite, postgresql ]
os: [ ubuntu-latest, windows-latest, macos-13 ]
exclude:
- db: postgresql
os: windows-latest
- db: postgresql
os: macos-13
env:
CI_TEST_DB_BACKEND: ${{ matrix.db }}
services:
postgres:
# Applying this workaround: https://github.com/actions/runner/issues/822
image: ${{ (matrix.os == 'ubuntu-latest') && 'postgres:12' || '' }}
image: ${{ (matrix.db == 'postgresql') && 'postgres:12' || '' }}
env:
POSTGRES_PASSWORD: phoenix
options: >-
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/python-cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
integration-test:
runs-on: ubuntu-latest
env:
CI_TEST_DB_BACKEND: postgresql
services:
postgres:
image: postgres:12
Expand Down
8 changes: 1 addition & 7 deletions tests/integration/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,7 @@ def _random_schema(
url: URL,
) -> Iterator[str]:
engine = create_engine(url.set(drivername="postgresql+psycopg"))
try:
engine.connect().close()
except OperationalError as exc:
if "too many clients" in str(exc):
pass
else:
pytest.skip(f"PostgreSQL unavailable: {exc}")
engine.connect().close()
engine.dispose()
schema = f"_{secrets.token_hex(15)}"
yield schema
Expand Down
18 changes: 7 additions & 11 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,14 @@ def _(used: List[int]) -> Iterator[int]:
return _([])


@pytest.fixture(
scope="session",
params=[
pytest.param("sqlite:///:memory:", id="sqlite"),
pytest.param(
"postgresql://127.0.0.1:5432/postgres?user=postgres&password=phoenix",
id="postgresql",
),
],
)
@pytest.fixture(scope="session")
def _sql_database_url(request: SubRequest) -> URL:
return make_url(request.param)
backend = os.getenv("CI_TEST_DB_BACKEND")
if not backend or backend == "sqlite":
return make_url("sqlite:///:memory:")
if backend == "postgresql":
return make_url("postgresql://127.0.0.1:5432/postgres?user=postgres&password=phoenix")
pytest.fail(f"Unknown database backend: {backend}")


@pytest.fixture(scope="session", params=["http", "grpc"])
Expand Down
4 changes: 4 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ commands =
; pytest -ra -x {posargs:.}

[testenv:ci_integration_tests]
pass_env =
CI_TEST_DB_BACKEND
changedir = tests/integration
deps =
-r requirements/integration-tests.txt
Expand Down Expand Up @@ -63,6 +65,8 @@ commands =
; pytest {posargs:.}

[testenv:integration_tests]
pass_env =
CI_TEST_DB_BACKEND
changedir = tests/integration
deps =
-r requirements/integration-tests.txt
Expand Down

0 comments on commit 4b8eec3

Please sign in to comment.