From 61c10e4f2d053730e95c0a93f6a7db91a7041900 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 31 Jan 2024 16:12:56 +0100 Subject: [PATCH] ci: update tox.ini + py311 compatibility (#86371) * separate codestyle target from test * remove dead pylint target * separate test dependencies in requirement file * update pre-commit hooks * launch coverage/junit tally when in jenkins * use tempdir fixture instead of tempfile --- .pre-commit-config.yaml | 24 +++++++++++++++------- Jenkinsfile | 1 - pylint.sh | 16 --------------- test-requirements.txt | 7 +++++++ tests/conftest.py | 7 ++++++- tests/settings.py | 15 +------------- tox.ini | 45 +++++++++++++++++++---------------------- 7 files changed, 52 insertions(+), 63 deletions(-) delete mode 100755 pylint.sh create mode 100644 test-requirements.txt diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3613b51..51fea69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,21 +5,31 @@ repos: rev: v4.4.0 hooks: - id: double-quote-string-fixer +- repo: https://github.com/asottile/pyupgrade + rev: v3.3.1 + hooks: + - id: pyupgrade + args: ['--keep-percent-format', '--py39-plus'] +- repo: https://github.com/adamchainz/django-upgrade + rev: 1.13.0 + hooks: + - id: django-upgrade + args: ['--target-version', '3.2'] - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.1.0 hooks: - id: black - args: ['--target-version', 'py37', '--skip-string-normalization', '--line-length', '110'] + args: ['--target-version', 'py39', '--skip-string-normalization', '--line-length', '110'] - repo: https://github.com/PyCQA/isort rev: 5.12.0 hooks: - id: isort args: ['--profile', 'black', '--line-length', '110'] -- repo: https://github.com/asottile/pyupgrade - rev: v3.1.0 - hooks: - - id: pyupgrade - args: ['--keep-percent-format', '--py37-plus'] +- repo: https://github.com/rtts/djhtml + rev: '3.0.5' + hooks: + - id: djhtml + args: ['--tabwidth', '2'] - repo: https://git.entrouvert.org/pre-commit-debian.git rev: v0.3 hooks: diff --git a/Jenkinsfile b/Jenkinsfile index 74a94be..03b51e0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,7 +13,6 @@ pipeline { utils = new Utils() utils.publish_coverage('coverage.xml') utils.publish_coverage_native('index.html') - utils.publish_pylint('pylint.out') } mergeJunitResults() } diff --git a/pylint.sh b/pylint.sh deleted file mode 100755 index babdf18..0000000 --- a/pylint.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh - -set -e -x -env -if [ -f /var/lib/jenkins/pylint.django.rc ]; then - PYLINT_RC=/var/lib/jenkins/pylint.django.rc -elif [ -f pylint.django.rc ]; then - PYLINT_RC=pylint.django.rc -else - echo No pylint RC found - exit 0 -fi - -test -f pylint.out && cp pylint.out pylint.out.prev -pylint -f parseable --rcfile ${PYLINT_RC} "$@" | tee pylint.out || /bin/true -test -f pylint.out.prev && (diff pylint.out.prev pylint.out | grep '^[><]' | grep .py) || /bin/true diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..8e05c18 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,7 @@ +psycopg2-binary +django-webtest +pytest +pytest-cov +pytest-random +pytest-django +pytest-freezer diff --git a/tests/conftest.py b/tests/conftest.py index d079619..d477fd3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,3 @@ -# fargo - document box # Copyright (C) 2016-2019 Entr'ouvert # # This program is free software: you can redistribute it and/or modify it @@ -29,6 +28,12 @@ class WebTestMixin(django_webtest.WebTestMixin): csrf_checks = False +@pytest.fixture(autouse=True) +def media(settings, tmpdir): + settings.MEDIA_ROOT = str(tmpdir.mkdir('media')) + return settings.MEDIA_ROOT + + @pytest.fixture def app(request): wtm = WebTestMixin() diff --git a/tests/settings.py b/tests/settings.py index ec0aa49..c65376b 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -14,22 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import os -import tempfile - DEBUG = False ALLOWED_HOSTS = ['*'] LANGUAGE_CODE = 'en-US' -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.' + os.environ.get('DB_ENGINE', 'sqlite3'), - 'NAME': 'fargo.sqlite3', - 'TEST': { - 'NAME': 'fargo-test-' + os.environ.get('DB_ENGINE', 'sqlite3'), - }, - } -} - -MEDIA_ROOT = tempfile.mkdtemp('fargo-test') +DATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql', 'NAME': 'fargo'}} diff --git a/tox.ini b/tox.ini index 600b278..4e11ff4 100644 --- a/tox.ini +++ b/tox.ini @@ -1,39 +1,36 @@ [tox] toxworkdir = {env:TMPDIR:/tmp}/tox-{env:USER}/fargo/{env:BRANCH_NAME:} -envlist = - py3-dj32-black-coverage-pylint - py3-dj22 +envlist = py3,codestyle [testenv] usedevelop = True whitelist_externals = /bin/mv setenv = - DB_ENGINE=postgresql_psycopg2 DJANGO_SETTINGS_MODULE=fargo.settings FARGO_SETTINGS_FILE=tests/settings.py - SETUPTOOLS_USE_DISTUTILS=stdlib - coverage: COVERAGE=--junitxml=junit-{envname}.xml --random --cov-report xml --cov-report html --cov=fargo/ + JUNIT={tty::-o junit_suite_name={envname} --junit-xml=junit-{envname}.xml} + COVERAGE={tty::--cov --cov-append --cov-report xml --cov-report html --cov-context=test --cov-config=tox.ini} deps = - pytest - psycopg2<2.9 - pylint<3 - astroid<3 - pylint-django - dj22: django>=2.2,<2.3 - dj32: django>=3.2,<3.3 + django>=3.2,<3.3 django-filter>=2.4,<23.2 django-tables2==2.4.1 - pytest-cov - pytest-random - pytest-mock - pytest-django - pytest-freezegun - django-webtest - WebTest - mock<4 + -r test-requirements.txt +commands = + py.test {env:JUNIT:} {env:COVERAGE:} {posargs:tests/} + +[testenv:codestyle] +skip_install = true +deps = pre-commit commands = - py.test {env:COVERAGE:} {posargs:tests/} - pylint: ./pylint.sh fargo/ - black: pre-commit run black --all-files --show-diff-on-failure + pre-commit run --all-files --show-diff-on-failure + +[coverage:run] +source = + fargo + tests +branch = True + +[coverage:html] +show_contexts = True