Skip to content

Commit 91117f9

Browse files
committed
ci(tox): add tox for multiple env test and also use it for CI
1 parent 716bc83 commit 91117f9

File tree

3 files changed

+122
-12
lines changed

3 files changed

+122
-12
lines changed

.github/workflows/test.yml

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,22 @@ jobs:
1818
GITHUB_CONTEXT: ${{ toJson(github) }}
1919
run: echo "$GITHUB_CONTEXT"
2020
- uses: actions/checkout@v4
21-
- name: Install the latest version of uv and set the python version to 3.13t
21+
- name: Install the latest version of uv and set the python version
2222
uses: astral-sh/setup-uv@v5
2323
with:
2424
enable-cache: true
2525
python-version: 3.11
26-
- name: Lint
27-
run: uv run bash scripts/lint.sh
26+
- name: Install tox with uv
27+
run: uv tool install tox --with tox-uv
28+
- name: Run lint with tox
29+
run: tox -e lint
2830

2931
test:
3032
runs-on: ubuntu-latest
3133
strategy:
3234
matrix:
3335
python-version: ["3.11", "3.12", "3.13"]
36+
django-version: ["5"]
3437
fail-fast: false
3538
services:
3639
postgres:
@@ -73,14 +76,61 @@ jobs:
7376
with:
7477
enable-cache: true
7578
python-version: ${{ matrix.python-version }}
76-
- run: mkdir coverage
77-
- name: Test
78-
run: uv run --group test --all-extras coverage run -m pytest sandbox
79+
- name: Install tox with uv
80+
run: uv tool install tox --with tox-uv
81+
- name: Run tests with tox
82+
run: tox -e py${{ matrix.python-version }}-django${{ matrix.django-version }}
83+
84+
coverage:
85+
runs-on: ubuntu-latest
86+
services:
87+
postgres:
88+
image: postgres
89+
env:
90+
POSTGRES_PASSWORD: chanx_test_pass
91+
POSTGRES_DB: chanx_test_db
92+
POSTGRES_USER: chanx_test_user
93+
options: >-
94+
--health-cmd pg_isready
95+
--health-interval 10s
96+
--health-timeout 5s
97+
--health-retries 5
98+
ports:
99+
- 5432:5432
100+
redis:
101+
image: redis
102+
options: >-
103+
--health-cmd "redis-cli ping"
104+
--health-interval 10s
105+
--health-timeout 5s
106+
--health-retries 5
107+
ports:
108+
- 6379:6379
109+
env:
110+
POSTGRES_DB: chanx_test_db
111+
POSTGRES_USER: chanx_test_user
112+
POSTGRES_PASSWORD: chanx_test_pass
113+
POSTGRES_HOST: localhost
114+
POSTGRES_PORT: 5432
115+
REDIS_HOST: redis://localhost:6379
116+
steps:
117+
- name: Dump GitHub context
79118
env:
80-
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
81-
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
82-
- name: Store coverage files
83-
uses: actions/upload-artifact@v4
119+
GITHUB_CONTEXT: ${{ toJson(github) }}
120+
run: echo "$GITHUB_CONTEXT"
121+
- uses: actions/checkout@v4
122+
- name: Install the latest version of uv and set the python version
123+
uses: astral-sh/setup-uv@v5
124+
with:
125+
enable-cache: true
126+
python-version: "3.11"
127+
- name: Install tox with uv
128+
run: uv tool install tox --with tox-uv
129+
- name: Run coverage with tox
130+
run: tox -e coverage
131+
- name: Upload coverage reports to Codecov
132+
uses: codecov/codecov-action@v4
84133
with:
85-
name: coverage
86-
path: coverage
134+
token: ${{ secrets.CODECOV_TOKEN }}
135+
file: ./coverage.xml
136+
fail_ci_if_error: false

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ exclude = '''
102102
| \.vscode
103103
| __pycache__
104104
| .venv
105+
| .tox
105106
| build
106107
| coverage
107108
)/

tox.ini

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[tox]
2+
env_list = py311-django5, py312-django5, py313-django5, lint, coverage
3+
isolated_build = True
4+
5+
[testenv]
6+
allowlist_externals =
7+
pytest
8+
py
9+
python
10+
package = uv
11+
extras = dev, test
12+
runner = uv-venv-runner
13+
setenv =
14+
PYTHONPATH = {toxinidir}
15+
DJANGO_SETTINGS_MODULE = config.settings.test
16+
commands =
17+
pytest {posargs:sandbox}
18+
19+
[testenv:py311-django5]
20+
package = uv
21+
extras = dev, test
22+
basepython = python3.11
23+
24+
[testenv:py312-django5]
25+
package = uv
26+
extras = dev, test
27+
basepython = python3.12
28+
29+
[testenv:py313-django5]
30+
package = uv
31+
extras = dev, test
32+
basepython = python3.13
33+
34+
[testenv:lint]
35+
allowlist_externals =
36+
black
37+
ruff
38+
mypy
39+
package = uv
40+
extras = lint
41+
commands =
42+
black --check chanx
43+
ruff check chanx
44+
mypy chanx
45+
46+
[testenv:coverage]
47+
allowlist_externals =
48+
pytest
49+
package = uv
50+
extras = dev, test
51+
commands =
52+
pytest --cov-report term-missing --cov=chanx sandbox
53+
54+
[pytest]
55+
DJANGO_SETTINGS_MODULE = config.settings.test
56+
filterwarnings =
57+
ignore::DeprecationWarning
58+
ignore:app_settings.USERNAME_REQUIRED is deprecated:UserWarning:dj_rest_auth.*
59+
ignore:app_settings.EMAIL_REQUIRED is deprecated:UserWarning:dj_rest_auth.*

0 commit comments

Comments
 (0)