From 27ccd6a3f1c8c604eb1e1549eb91fe437a76a802 Mon Sep 17 00:00:00 2001 From: Anto59290 Date: Fri, 21 Jun 2024 09:45:48 +0200 Subject: [PATCH] Ajout d'une configuration pour la CI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Permet de lancer les tests et ruff à chaque commit - Réduit le timeout à 2 secondes par page afin que les test prennents moins de temps en cas de problème / attente du navigateur - Lance les tests en parallèle en fonction des capacités de la machine - Lance le formatage des templates en excluant les dépendances https://github.com/rtts/djhtml/issues/48 --- .github/workflows/django.yml | 32 ++++++++++++++++++++++++++++++++ pytest.ini | 1 + sv/tests/conftest.py | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100644 .github/workflows/django.yml diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml new file mode 100644 index 00000000..1262f1af --- /dev/null +++ b/.github/workflows/django.yml @@ -0,0 +1,32 @@ +name: Django application +on: [push] +jobs: + build: + runs-on: ubuntu-latest + services: + postgres: + image: postgres:latest + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: github_actions + ports: + - 5432:5432 + # needed because the postgres container does not provide a healthcheck + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.11.1 + - name: Install dependencies + run: pip install pip-tools && pip-sync && playwright install + - name: Run ruff + run: ruff check . + - name: Run DjHTML + run: find -name *.html -not -path "./venv/*" | xargs djhtml + - name: Run tests + run: pytest + env: + SECRET_KEY: NOT_A_REAL_SECRET + DATABASE_URL: postgres://postgres:postgres@localhost/github_actions diff --git a/pytest.ini b/pytest.ini index 0aeafcd5..e243ab3e 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] DJANGO_SETTINGS_MODULE = seves.settings python_files = test_*.py +addopts = -nauto \ No newline at end of file diff --git a/sv/tests/conftest.py b/sv/tests/conftest.py index 7564409d..b8b6a593 100644 --- a/sv/tests/conftest.py +++ b/sv/tests/conftest.py @@ -7,6 +7,13 @@ from sv.models import Etat, FicheDetection +@pytest.fixture +def page(page): + timeout = 2_000 + page.set_default_navigation_timeout(timeout) + page.set_default_timeout(timeout) + yield page + @pytest.fixture(scope="module", autouse=True) def set_django_allow_async_unsafe(): os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"