Skip to content

Migrate the pytest invocation to tox #662

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

Merged
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
117 changes: 99 additions & 18 deletions .github/workflows/test-library.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 \
Expand All @@ -52,7 +40,7 @@ jobs:
&
./tests/integration/main.sh

tox:
lint:
name: ${{ matrix.toxenv }}

runs-on: Ubuntu-latest
Expand Down Expand Up @@ -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/[email protected]
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

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down