From 7c5877b74a62e796274ca5060de49146e283f3fa Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 4 Nov 2021 13:17:23 +0100 Subject: [PATCH] Migrate the pytest invocation to `tox` (#662) * Fix the `commands` setting in the tox config * Wire up `pytest` invocations via tox --- .github/workflows/test-library.yml | 117 ++++++++++++++++++++++++----- Makefile | 2 +- tox.ini | 6 +- 3 files changed, 105 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test-library.yml b/.github/workflows/test-library.yml index d2d93fad..a1efa593 100644 --- a/.github/workflows/test-library.yml +++ b/.github/workflows/test-library.yml @@ -13,12 +13,12 @@ concurrency: cancel-in-progress: true jobs: - build: + integration: runs-on: ${{ matrix.os }}-latest name: Library - Python ${{ matrix.python }} on ${{ matrix.os }} strategy: matrix: - os: [macOS, ubuntu, windows] + os: [macOS, Ubuntu] python: ['3.6', '3.7', '3.8', '3.9', '3.10'] max-parallel: 4 fail-fast: false @@ -28,21 +28,9 @@ jobs: uses: actions/setup-python@v2 with: python-version: ${{ matrix.python }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r requirements-testing.txt - pip install -r requirements-tunnel.txt - - name: Run Tests - run: pytest --cov=proxy tests/ - - name: Upload coverage to Codecov - env: - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - run: codecov - name: Integration testing - if: matrix.os != 'windows' run: | + pip install -U pip pip install . proxy \ --hostname 127.0.0.1 \ @@ -52,7 +40,7 @@ jobs: & ./tests/integration/main.sh - tox: + lint: name: ${{ matrix.toxenv }} runs-on: Ubuntu-latest @@ -129,10 +117,103 @@ jobs: --parallel-live --skip-missing-interpreters false + test: + name: 🐍${{ matrix.python }} @ ${{ matrix.os }} + + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: + - macOS + - Ubuntu + - Windows + python: + # NOTE: The latest and the lowest supported Pythons are prioritized + # NOTE: to improve the responsiveness. It's nice to see the most + # NOTE: important results first. + - '3.10' + - 3.6 + - 3.9 + - 3.8 + - 3.7 + max-parallel: 4 + + env: + PY_COLORS: 1 + TOX_PARALLEL_NO_SPINNER: 1 + TOXENV: python + + steps: + - name: Switch to using Python v${{ matrix.python }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python }} + - name: >- + Calculate Python interpreter version hash value + for use in the cache key + id: calc-cache-key-py + run: | + from hashlib import sha512 + from sys import version + + hash = sha512(version.encode()).hexdigest() + print(f'::set-output name=py-hash-key::{hash}') + shell: python + - name: Get pip cache dir + id: pip-cache + run: >- + echo "::set-output name=dir::$(pip cache dir)" + - name: Set up pip cache + uses: actions/cache@v2.1.5 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: >- + ${{ runner.os }}-pip-${{ + steps.calc-cache-key-py.outputs.py-hash-key }}-${{ + hashFiles('tox.ini', 'requirements.txt', 'requirements-testing.txt') + }} + restore-keys: | + ${{ runner.os }}-pip-${{ + steps.calc-cache-key-py.outputs.py-hash-key + }}- + ${{ runner.os }}-pip- + - name: Install tox + run: >- + python -m + pip install + --user + tox + + - name: Grab the source from Git + uses: actions/checkout@v2 + + - name: Pre-populate the testing env + run: >- + python -m + tox + --parallel auto + --parallel-live + --skip-missing-interpreters false + --notest + - name: Run the testing + run: >- + python -m + tox + --parallel auto + --parallel-live + --skip-missing-interpreters false + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v2 + with: + flags: pytest, GHA, Python ${{ matrix.python }}, ${{ runner.os }} + verbose: true + check: # This job does nothing and is only used for the branch protection needs: - - build - - tox + - integration + - lint + - test runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index ea356d86..66dcd365 100644 --- a/Makefile +++ b/Makefile @@ -92,7 +92,7 @@ lib-lint: python -m tox -e lint lib-test: lib-clean lib-version lib-lint - pytest -v tests/ + python -m tox -e python -- -v lib-package: lib-clean lib-version python -m tox -e cleanup-dists,build-dists,metadata-validation diff --git a/tox.ini b/tox.ini index c0090871..370e1293 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,11 @@ minversion = 3.21.0 deps = -rrequirements.txt -rrequirements-testing.txt -command = pytest +# NOTE: The command is invoked by the script name and not via +# NOTE: `{envpython} -m pytest` because it'd add CWD into $PYTHONPATH +# NOTE: testing the project from the Git checkout +# NOTE: rather than one installed. +commands = pytest --cov=proxy tests/ {posargs:} [dists]