Skip to content

Commit 7c5877b

Browse files
authored
Migrate the pytest invocation to tox (#662)
* Fix the `commands` setting in the tox config * Wire up `pytest` invocations via tox
1 parent 05a7856 commit 7c5877b

File tree

3 files changed

+105
-20
lines changed

3 files changed

+105
-20
lines changed

.github/workflows/test-library.yml

+99-18
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16-
build:
16+
integration:
1717
runs-on: ${{ matrix.os }}-latest
1818
name: Library - Python ${{ matrix.python }} on ${{ matrix.os }}
1919
strategy:
2020
matrix:
21-
os: [macOS, ubuntu, windows]
21+
os: [macOS, Ubuntu]
2222
python: ['3.6', '3.7', '3.8', '3.9', '3.10']
2323
max-parallel: 4
2424
fail-fast: false
@@ -28,21 +28,9 @@ jobs:
2828
uses: actions/setup-python@v2
2929
with:
3030
python-version: ${{ matrix.python }}
31-
- name: Install dependencies
32-
run: |
33-
python -m pip install --upgrade pip
34-
pip install -r requirements.txt
35-
pip install -r requirements-testing.txt
36-
pip install -r requirements-tunnel.txt
37-
- name: Run Tests
38-
run: pytest --cov=proxy tests/
39-
- name: Upload coverage to Codecov
40-
env:
41-
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
42-
run: codecov
4331
- name: Integration testing
44-
if: matrix.os != 'windows'
4532
run: |
33+
pip install -U pip
4634
pip install .
4735
proxy \
4836
--hostname 127.0.0.1 \
@@ -52,7 +40,7 @@ jobs:
5240
&
5341
./tests/integration/main.sh
5442
55-
tox:
43+
lint:
5644
name: ${{ matrix.toxenv }}
5745

5846
runs-on: Ubuntu-latest
@@ -129,10 +117,103 @@ jobs:
129117
--parallel-live
130118
--skip-missing-interpreters false
131119
120+
test:
121+
name: 🐍${{ matrix.python }} @ ${{ matrix.os }}
122+
123+
runs-on: ${{ matrix.os }}-latest
124+
strategy:
125+
fail-fast: false
126+
matrix:
127+
os:
128+
- macOS
129+
- Ubuntu
130+
- Windows
131+
python:
132+
# NOTE: The latest and the lowest supported Pythons are prioritized
133+
# NOTE: to improve the responsiveness. It's nice to see the most
134+
# NOTE: important results first.
135+
- '3.10'
136+
- 3.6
137+
- 3.9
138+
- 3.8
139+
- 3.7
140+
max-parallel: 4
141+
142+
env:
143+
PY_COLORS: 1
144+
TOX_PARALLEL_NO_SPINNER: 1
145+
TOXENV: python
146+
147+
steps:
148+
- name: Switch to using Python v${{ matrix.python }}
149+
uses: actions/setup-python@v2
150+
with:
151+
python-version: ${{ matrix.python }}
152+
- name: >-
153+
Calculate Python interpreter version hash value
154+
for use in the cache key
155+
id: calc-cache-key-py
156+
run: |
157+
from hashlib import sha512
158+
from sys import version
159+
160+
hash = sha512(version.encode()).hexdigest()
161+
print(f'::set-output name=py-hash-key::{hash}')
162+
shell: python
163+
- name: Get pip cache dir
164+
id: pip-cache
165+
run: >-
166+
echo "::set-output name=dir::$(pip cache dir)"
167+
- name: Set up pip cache
168+
uses: actions/[email protected]
169+
with:
170+
path: ${{ steps.pip-cache.outputs.dir }}
171+
key: >-
172+
${{ runner.os }}-pip-${{
173+
steps.calc-cache-key-py.outputs.py-hash-key }}-${{
174+
hashFiles('tox.ini', 'requirements.txt', 'requirements-testing.txt')
175+
}}
176+
restore-keys: |
177+
${{ runner.os }}-pip-${{
178+
steps.calc-cache-key-py.outputs.py-hash-key
179+
}}-
180+
${{ runner.os }}-pip-
181+
- name: Install tox
182+
run: >-
183+
python -m
184+
pip install
185+
--user
186+
tox
187+
188+
- name: Grab the source from Git
189+
uses: actions/checkout@v2
190+
191+
- name: Pre-populate the testing env
192+
run: >-
193+
python -m
194+
tox
195+
--parallel auto
196+
--parallel-live
197+
--skip-missing-interpreters false
198+
--notest
199+
- name: Run the testing
200+
run: >-
201+
python -m
202+
tox
203+
--parallel auto
204+
--parallel-live
205+
--skip-missing-interpreters false
206+
- name: Upload coverage to Codecov
207+
uses: codecov/codecov-action@v2
208+
with:
209+
flags: pytest, GHA, Python ${{ matrix.python }}, ${{ runner.os }}
210+
verbose: true
211+
132212
check: # This job does nothing and is only used for the branch protection
133213
needs:
134-
- build
135-
- tox
214+
- integration
215+
- lint
216+
- test
136217

137218
runs-on: ubuntu-latest
138219

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ lib-lint:
9292
python -m tox -e lint
9393

9494
lib-test: lib-clean lib-version lib-lint
95-
pytest -v tests/
95+
python -m tox -e python -- -v
9696

9797
lib-package: lib-clean lib-version
9898
python -m tox -e cleanup-dists,build-dists,metadata-validation

tox.ini

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ minversion = 3.21.0
77
deps =
88
-rrequirements.txt
99
-rrequirements-testing.txt
10-
command = pytest
10+
# NOTE: The command is invoked by the script name and not via
11+
# NOTE: `{envpython} -m pytest` because it'd add CWD into $PYTHONPATH
12+
# NOTE: testing the project from the Git checkout
13+
# NOTE: rather than one installed.
14+
commands = pytest --cov=proxy tests/ {posargs:}
1115

1216

1317
[dists]

0 commit comments

Comments
 (0)