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

Run tests on github actions both for sqlite and postgresql #260

Merged
merged 3 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 22 additions & 2 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ jobs:

runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
# Maps tcp port 5432 on service container to the host
- 5432:5432


steps:
- uses: actions/checkout@v3
- name: Apt update
Expand Down Expand Up @@ -44,8 +59,13 @@ jobs:
- name: Statics checks
run: ./manage.py collectstatic --noinput -v 0

- name: pytest
- name: pytest with SQLite
run: pytest -k "not unoconv"

- name: database checks
- name: pytest with PostgreSQL
run: pytest -k "not unoconv" -m postgresql
env:
DB_URL: postgres://postgres:postgres@localhost:5432/postgres

- name: Check local dev initialization scripts
run: make database
28 changes: 28 additions & 0 deletions search/tests/test_postgresql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import connection

import pytest


def needs_postgres(fn):
@pytest.mark.django_db
@pytest.mark.postgresql
@pytest.mark.skipif(
connection.vendor != "postgresql",
reason="This test requires a PostgreSQL database",
)
def wrapper(*args, **kwargs):
return fn(*args, **kwargs)

return wrapper


@needs_postgres
def test_running_with_postgres():
"""
This is a dummy test to check if our logic of @needs_postgres is correct
and that the setup of GitHub actions is correct too.
"""
assert True


# FIXME: add more tests (see https://github.com/UrLab/DocHub/issues/257)
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ markers =
unoconv: uses unoconv (underterministic)
webtest: http queries against localhost
celery: uses celery tasks
postgresql: needs a postgresql database to run

[flake8]
ignore = E261
Expand Down