From: Daniele Varrazzo Date: Thu, 8 Dec 2022 14:44:36 +0000 (+0000) Subject: ci: drop tox from tests X-Git-Tag: pool-3.1.5~5^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd1652242672a971a6cb250d6dfb1b1379681c5c;p=thirdparty%2Fpsycopg.git ci: drop tox from tests --- diff --git a/.flake8 b/.flake8 new file mode 100644 index 000000000..ec4053fb2 --- /dev/null +++ b/.flake8 @@ -0,0 +1,7 @@ +[flake8] +max-line-length = 88 +ignore = W503, E203 +extend-exclude = .venv build +per-file-ignores = + # Autogenerated section + psycopg/psycopg/errors.py: E125, E128, E302 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index e891abf11..452755100 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -18,18 +18,31 @@ jobs: steps: - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 - - name: Install tox - run: pip install "tox < 4" + with: + python-version: "3.10" + + - name: install packages to tests + run: pip install ./psycopg[dev,test] codespell + - name: Run black - run: tox -e black + run: black --check --diff . + - name: Run flake8 - run: tox -e flake8 + run: flake8 + - name: Run mypy - run: tox -e mypy + run: mypy + - name: Check spelling - run: tox -e codespell + run: codespell + - name: Install requirements to generate docs run: sudo apt-get install -y libgeos-dev + + - name: Install Python packages to generate docs + run: pip install ./psycopg[docs] ./psycopg_pool + - name: Check documentation - run: tox -e docs + run: sphinx-build -W -T -b html docs docs/_build/html diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c438a7ce5..2c43a5a4e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,32 +19,35 @@ jobs: linux: # {{{ runs-on: ubuntu-latest + if: true strategy: fail-fast: false matrix: include: # Test different combinations of Python, Postgres, libpq. - - {impl: python, python: "3.7", postgres: "postgres:10", libpq: "newest"} - - {impl: python, python: "3.8", postgres: "postgres:12", libpq: ""} - - {impl: python, python: "3.9", postgres: "postgres:13", libpq: ""} - - {impl: python, python: "3.10", postgres: "postgres:14", libpq: ""} - - {impl: python, python: "3.11", postgres: "postgres:15", libpq: "oldest"} + - {impl: python, python: "3.7", postgres: "postgres:10", libpq: newest} + - {impl: python, python: "3.8", postgres: "postgres:12"} + - {impl: python, python: "3.9", postgres: "postgres:13"} + - {impl: python, python: "3.10", postgres: "postgres:14"} + - {impl: python, python: "3.11", postgres: "postgres:15", libpq: oldest} - - {impl: c, python: "3.7", postgres: "postgres:15", libpq: "newest"} - - {impl: c, python: "3.8", postgres: "postgres:13", libpq: ""} - - {impl: c, python: "3.9", postgres: "postgres:14", libpq: ""} - - {impl: c, python: "3.10", postgres: "postgres:13", libpq: "oldest"} - - {impl: c, python: "3.11", postgres: "postgres:10", libpq: "newest"} + - {impl: c, python: "3.7", postgres: "postgres:15", libpq: newest} + - {impl: c, python: "3.8", postgres: "postgres:13"} + - {impl: c, python: "3.9", postgres: "postgres:14"} + - {impl: c, python: "3.10", postgres: "postgres:13", libpq: oldest} + - {impl: c, python: "3.11", postgres: "postgres:10", libpq: newest} - - {impl: dns, python: "3.9", postgres: "postgres:14", libpq: ""} - - {impl: postgis, python: "3.9", postgres: "postgis/postgis", libpq: ""} + - {impl: python, python: "3.9", ext: dns, postgres: "postgres:14"} + - {impl: python, python: "3.9", ext: postgis, postgres: "postgis/postgis"} env: PSYCOPG_IMPL: ${{ matrix.impl }} + DEPS: ./psycopg[test] ./psycopg_pool PSYCOPG_TEST_DSN: "host=127.0.0.1 user=postgres" PGPASSWORD: password - PYTEST_ADDOPTS: --color yes + MARKERS: "" + # Enable to run tests using the minimum version of dependencies. # PIP_CONSTRAINT: ${{ github.workspace }}/tests/constraints.txt @@ -85,31 +88,29 @@ jobs: sudo apt-get -qq -y --allow-downgrades install \ "libpq-dev=${pqver}" "libpq5=${pqver}" - - name: Install tox - # https://github.com/tox-dev/tox/issues/2619 - run: pip install "tox < 4" + - if: ${{ matrix.ext == 'dns' }} + run: | + echo "DEPS=$DEPS dnspython" >> $GITHUB_ENV + echo "MARKERS=$MARKERS dns" >> $GITHUB_ENV - - name: Run tests (Python implementation) - if: ${{ matrix.impl == 'python' }} - run: tox -c psycopg -e ${{ matrix.python }} + - if: ${{ matrix.ext == 'postgis' }} + run: | + echo "DEPS=$DEPS shapely" >> $GITHUB_ENV + echo "MARKERS=$MARKERS postgis" >> $GITHUB_ENV - - name: Run tests (C implementation) - if: ${{ matrix.impl == 'c' }} + - if: ${{ matrix.impl == 'c' }} # skip tests failing on importing psycopg_c.pq on subprocess # they only fail on Travis, work ok locally under tox too. - run: tox -c psycopg_c -e ${{ matrix.python }} -- -m 'not subprocess' + # TODO: check the same on GitHub Actions + run: | + echo "DEPS=$DEPS ./psycopg_c" >> $GITHUB_ENV + echo "NOT_MARKERS=$NOT_MARKERS subprocess" >> $GITHUB_ENV - - name: Run DNS-related tests - if: ${{ matrix.impl == 'dns' }} - run: tox -c psycopg -e dns -- -m dns - env: - PSYCOPG_IMPL: python + - name: Install Python dependencies + run: pip install $DEPS - - name: Run PostGIS-related tests - if: ${{ matrix.impl == 'postgis' }} - run: tox -c psycopg -e postgis -- -m postgis - env: - PSYCOPG_IMPL: python + - name: Run tests + run: ./tools/build/ci_test.sh services: postgresql: @@ -130,6 +131,7 @@ jobs: macos: # {{{ runs-on: macos-latest + if: true strategy: fail-fast: false @@ -148,11 +150,12 @@ jobs: env: PSYCOPG_IMPL: ${{ matrix.impl }} + DEPS: ./psycopg[test] ./psycopg_pool PSYCOPG_TEST_DSN: "host=127.0.0.1 user=runner dbname=postgres" # MacOS on GitHub Actions seems particularly slow. # Don't run timing-based tests as they regularly fail. # pproxy-based tests fail too, with the proxy not coming up in 2s. - PYTEST_ADDOPTS: -m 'not timing and not proxy and not mypy' --color yes + NOT_MARKERS: "timing proxy mypy" # PIP_CONSTRAINT: ${{ github.workspace }}/tests/constraints.txt steps: @@ -168,22 +171,25 @@ jobs: with: python-version: ${{ matrix.python }} - - name: Install tox - run: pip install "tox < 4" + - if: ${{ matrix.impl == 'c' }} + # skip tests failing on importing psycopg_c.pq on subprocess + # they only fail on Travis, work ok locally under tox too. + # TODO: check the same on GitHub Actions + run: | + echo "DEPS=$DEPS ./psycopg_c" >> $GITHUB_ENV - - name: Run tests (Python implementation) - if: ${{ matrix.impl == 'python' }} - run: tox -c psycopg -e ${{ matrix.python }} + - name: Install Python dependencies + run: pip install $DEPS - - name: Run tests (C implementation) - if: ${{ matrix.impl == 'c' }} - run: tox -c psycopg_c -e ${{ matrix.python }} + - name: Run tests + run: ./tools/build/ci_test.sh # }}} windows: # {{{ runs-on: windows-latest + if: true strategy: fail-fast: false @@ -202,9 +208,10 @@ jobs: env: PSYCOPG_IMPL: ${{ matrix.impl }} + DEPS: ./psycopg[test] ./psycopg_pool PSYCOPG_TEST_DSN: "host=127.0.0.1 dbname=postgres" # On windows pproxy doesn't seem very happy. Also a few timing test fail. - PYTEST_ADDOPTS: -m 'not timing and not proxy and not mypy' --color yes + NOT_MARKERS: "timing proxy mypy" # PIP_CONSTRAINT: ${{ github.workspace }}/tests/constraints.txt steps: @@ -220,57 +227,43 @@ jobs: with: python-version: ${{ matrix.python }} - - name: Install tox - run: pip install "tox < 4" wheel - - - name: Run tests (Python implementation) - if: ${{ matrix.impl == 'python' }} - run: tox -c psycopg -e ${{ matrix.python }} - # Build a wheel package of the C extensions. # If the wheel is not delocated, import fails with some dll not found # (but it won't tell which one). - name: Build the C wheel if: ${{ matrix.impl == 'c' }} run: | + pip install delvewheel wheel $env:Path = "C:\Program Files\PostgreSQL\14\bin\;$env:Path" python ./psycopg_c/setup.py bdist_wheel - pip install delvewheel &"delvewheel" repair ` --no-mangle "libiconv-2.dll;libwinpthread-1.dll" ` @(Get-ChildItem psycopg_c\dist\*.whl) + &"pip" install @(Get-ChildItem wheelhouse\*.whl) - # tox will only build the package from sdist, not from wheel, so we can't - # use it for testing. Just test everything in the global installation. - - name: Install and run tests (C implementation) - if: ${{ matrix.impl == 'c' }} + - name: Run tests run: | - pip install ./psycopg/[test] ./psycopg_pool - &"pip" install @(Get-ChildItem wheelhouse\*.whl) - # Fix the path for the tests using ctypes - $env:Path = "C:\Program Files\PostgreSQL\14\bin\;$env:Path" - # We don't repeat failed tests as tox does. So allow one failure, - # typically reserved to a flakey test. - # We may hide a regular failure, yes, but then maybe a flakey test - # would allow us to find it... - pytest --allow-fail=1 + pip install $DEPS + ./tools/build/ci_test.sh + shell: bash # }}} crdb: # {{{ runs-on: ubuntu-latest + if: true strategy: fail-fast: false matrix: include: - - {crdb: "latest-v22.1", python: "3.10", impl: "c", libpq: "newest"} - - {crdb: "latest-v22.2", python: "3.11", impl: "python", libpq: ""} + - {impl: c, crdb: "latest-v22.1", python: "3.10", libpq: newest} + - {impl: python, crdb: "latest-v22.2", python: "3.11"} env: PSYCOPG_IMPL: ${{ matrix.impl }} + DEPS: ./psycopg[test] ./psycopg_pool PSYCOPG_TEST_DSN: "host=127.0.0.1 port=26257 user=root dbname=defaultdb" - PYTEST_ADDOPTS: --color yes steps: - uses: actions/checkout@v3 @@ -308,18 +301,19 @@ jobs: | awk '{print $2}') sudo apt-get -qq -y install "libpq-dev=${pqver}" "libpq5=${pqver}" - - name: Install tox - run: pip install "tox < 4" - - - name: Run tests (Python implementation) - if: ${{ matrix.impl == 'python' }} - run: tox -c psycopg -e ${{ matrix.python }} - - - name: Run tests (C implementation) - if: ${{ matrix.impl == 'c' }} + - if: ${{ matrix.impl == 'c' }} # skip tests failing on importing psycopg_c.pq on subprocess # they only fail on Travis, work ok locally under tox too. - run: tox -c psycopg_c -e ${{ matrix.python }} -- -m 'not subprocess' + # TODO: check the same on GitHub Actions + run: | + echo "DEPS=$DEPS ./psycopg_c" >> $GITHUB_ENV + echo "NOT_MARKERS=$NOT_MARKERS subprocess" >> $GITHUB_ENV + + - name: Install Python dependencies + run: pip install $DEPS + + - name: Run tests + run: ./tools/build/ci_test.sh - name: Stop CockroachDB run: docker kill crdb diff --git a/psycopg/.flake8 b/psycopg/.flake8 new file mode 100644 index 000000000..67fb0245c --- /dev/null +++ b/psycopg/.flake8 @@ -0,0 +1,6 @@ +[flake8] +max-line-length = 88 +ignore = W503, E203 +per-file-ignores = + # Autogenerated section + psycopg/errors.py: E125, E128, E302 diff --git a/psycopg/tox.ini b/psycopg/tox.ini deleted file mode 100644 index aa1c9dce3..000000000 --- a/psycopg/tox.ini +++ /dev/null @@ -1,40 +0,0 @@ -[tox] -envlist = {3.7,3.8,3.9,3.10,3.11} -isolated_build = True - -# Retry flakey tests by re-running the failed tests up to 3 times. -# -# - `--lfnf=none` makes pytest running no test (instead of all) if the previous -# run had no failure -# - `--no-collect-ok` changes the exit value from 5 to 0 if not test was -# collected (because the previous run was successful) -# - the `-` in front of the first two commands in tox makes it ignore failures, -# so that only the exit status of the last command is considered. -# -# This is *slightly* more complicated than what I'd hoped, but, ok. - -[testenv] -changedir = .. -commands = - -python -bb -m pytest {posargs} - -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} - python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} -passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT -extras = test -deps = - ../psycopg_pool - -[testenv:dns] -deps = - dnspython - -[testenv:postgis] -deps = - shapely - -[flake8] -max-line-length = 88 -ignore = W503, E203 -per-file-ignores = - # Autogenerated section - psycopg/errors.py: E125, E128, E302 diff --git a/psycopg_pool/tox.ini b/psycopg_c/.flake8 similarity index 100% rename from psycopg_pool/tox.ini rename to psycopg_c/.flake8 diff --git a/psycopg_c/tox.ini b/psycopg_c/tox.ini deleted file mode 100644 index 3b050e82e..000000000 --- a/psycopg_c/tox.ini +++ /dev/null @@ -1,18 +0,0 @@ -[tox] -envlist = {3.7,3.8,3.9,3.10,3.11} -isolated_build = True - -[testenv] -changedir = .. -commands = - -python -bb -m pytest {posargs} - -python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} - python -bb -m pytest --lf --lfnf=none --no-collect-ok --randomly-seed=last {posargs} -passenv = PG* PSYCOPG_TEST_* PYTEST_ADDOPTS PSYCOPG_IMPL PIP_CONSTRAINT -deps = - ../psycopg[test] - ../psycopg_pool - -[flake8] -max-line-length = 88 -ignore = W503, E203 diff --git a/psycopg_pool/.flake8 b/psycopg_pool/.flake8 new file mode 100644 index 000000000..2ae629c2d --- /dev/null +++ b/psycopg_pool/.flake8 @@ -0,0 +1,3 @@ +[flake8] +max-line-length = 88 +ignore = W503, E203 diff --git a/tests/conftest.py b/tests/conftest.py index 4d83f7ca5..9191e5769 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -73,10 +73,8 @@ def pytest_sessionstart(session): # Detect if there was a segfault in the previous run. # # In case of segfault, pytest doesn't get a chance to write failed tests - # in the cache. As a consequence, tox retries would find no test failed and + # in the cache. As a consequence, retries would find no test failed and # assume that all tests passed in the previous run, making the whole test pass. - # - # Note: The cache is in .pytest_cache/ cache = session.config.cache if cache.get("segfault", False): session.warn(Warning("Previous run resulted in segfault! Not running any test")) diff --git a/tools/build/ci_test.sh b/tools/build/ci_test.sh new file mode 100755 index 000000000..d1d2ee48f --- /dev/null +++ b/tools/build/ci_test.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Run the tests in Github Action +# +# Failed tests run up to three times, to take into account flakey tests. +# Of course the random generator is not re-seeded between runs, in order to +# repeat the same result. + +set -euo pipefail +set -x + +# Assemble a markers expression from the MARKERS and NOT_MARKERS env vars +markers="" +for m in ${MARKERS:-}; do + [[ "$markers" != "" ]] && markers="$markers and" + markers="$markers $m" +done +for m in ${NOT_MARKERS:-}; do + [[ "$markers" != "" ]] && markers="$markers and" + markers="$markers not $m" +done + +pytest="python -bb -m pytest --color=yes" + +$pytest -m "$markers" "$@" && exit 0 + +$pytest -m "$markers" --lf --randomly-seed=last "$@" && exit 0 + +$pytest -m "$markers" --lf --randomly-seed=last "$@" diff --git a/tox.ini b/tox.ini deleted file mode 100644 index 878be7720..000000000 --- a/tox.ini +++ /dev/null @@ -1,41 +0,0 @@ -[tox] -envlist = black, flake8, mypy, codespell, docs -isolated_build = True - -[testenv] -passenv = PIP_CONSTRAINT -skip_install = true - -[testenv:black] -commands = black --check --diff . -deps = - -e psycopg[dev] - -[testenv:flake8] -commands = flake8 -deps = - -e psycopg[dev] - -[testenv:mypy] -commands = mypy -deps = - -e psycopg[dev,test] - -[testenv:docs] -commands = sphinx-build -W -T -b html docs docs/_build/html -deps = - -e ./psycopg[docs] - -e ./psycopg_pool - -[testenv:codespell] -commands = codespell -deps = - codespell - -[flake8] -max-line-length = 88 -ignore = W503, E203 -extend-exclude = .venv -per-file-ignores = - # Autogenerated section - psycopg/psycopg/errors.py: E125, E128, E302