Skip to content

Commit b52b61a

Browse files
committed
Use more test factors to speed up tests.
1 parent 9b58a82 commit b52b61a

File tree

5 files changed

+192
-55
lines changed

5 files changed

+192
-55
lines changed

.github/workflows/test.yml

Lines changed: 152 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Test
33
on: [push, pull_request]
44

55
jobs:
6-
build:
6+
mysql:
77
runs-on: ubuntu-latest
88
strategy:
99
fail-fast: false
@@ -15,23 +15,78 @@ jobs:
1515
mariadb:
1616
image: mariadb:10.3
1717
env:
18-
MYSQL_ROOT_PASSWORD: debug_toolbar
19-
MYSQL_DATABASE: debug_toolbar
20-
ports:
21-
- 3306/tcp
18+
MYSQL_ROOT_PASSWORD: mysql
19+
MYSQL_DATABASE: mysql
2220
options: >-
2321
--health-cmd "mysqladmin ping"
2422
--health-interval 10s
2523
--health-timeout 5s
2624
--health-retries 5
25+
ports:
26+
- 3306:3306
27+
28+
steps:
29+
- uses: actions/checkout@v2
30+
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v2
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
36+
- name: Get pip cache dir
37+
id: pip-cache
38+
run: |
39+
echo "::set-output name=dir::$(pip cache dir)"
40+
41+
- name: Cache
42+
uses: actions/cache@v2
43+
with:
44+
path: ${{ steps.pip-cache.outputs.dir }}
45+
key:
46+
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/tox.ini') }}
47+
restore-keys: |
48+
${{ matrix.python-version }}-v1-
49+
50+
- name: Install enchant (only for docs)
51+
run: |
52+
sudo apt-get -qq update
53+
sudo apt-get -y install enchant
54+
55+
- name: Install dependencies
56+
run: |
57+
python -m pip install --upgrade pip
58+
python -m pip install --upgrade tox tox-gh-actions
59+
60+
- name: Test with tox
61+
run: tox
62+
env:
63+
DB_BACKEND: mysql
64+
DB_NAME: mysql
65+
DB_USER: root
66+
DB_PASSWORD: mysql
67+
DB_HOST: "127.0.0.1"
68+
DB_PORT: "3306"
69+
70+
- name: Upload coverage
71+
uses: codecov/codecov-action@v1
72+
with:
73+
name: Python ${{ matrix.python-version }}
74+
75+
postgres:
76+
runs-on: ubuntu-latest
77+
strategy:
78+
fail-fast: false
79+
max-parallel: 5
80+
matrix:
81+
python-version: ['3.6', '3.7', '3.8']
82+
83+
services:
2784
postgres:
2885
image: 'postgres:9.5'
2986
env:
30-
POSTGRES_USER: postgres
3187
POSTGRES_PASSWORD: postgres
32-
POSTGRES_DB: postgres
3388
ports:
34-
- 5432/tcp
89+
- 5432:5432
3590
options: >-
3691
--health-cmd pg_isready
3792
--health-interval 10s
@@ -70,13 +125,98 @@ jobs:
70125
python -m pip install --upgrade pip
71126
python -m pip install --upgrade tox tox-gh-actions
72127
73-
- name: Tox tests
74-
run: tox -v
128+
- name: Test with tox
129+
run: tox
75130
env:
76-
MYSQL_PORT: ${{ job.services.mariadb.ports[3306] }}
77-
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
131+
DB_BACKEND: postgresql
132+
DB_NAME: postgres
133+
DB_USER: postgres
134+
DB_PASSWORD: postgres
135+
DB_HOST: localhost
136+
DB_PORT: 5432
78137

79138
- name: Upload coverage
80139
uses: codecov/codecov-action@v1
81140
with:
82141
name: Python ${{ matrix.python-version }}
142+
143+
sqlite:
144+
runs-on: ubuntu-latest
145+
strategy:
146+
fail-fast: false
147+
max-parallel: 5
148+
matrix:
149+
python-version: ['3.6', '3.7', '3.8']
150+
151+
steps:
152+
- uses: actions/checkout@v2
153+
154+
- name: Set up Python ${{ matrix.python-version }}
155+
uses: actions/setup-python@v2
156+
with:
157+
python-version: ${{ matrix.python-version }}
158+
159+
- name: Get pip cache dir
160+
id: pip-cache
161+
run: |
162+
echo "::set-output name=dir::$(pip cache dir)"
163+
164+
- name: Cache
165+
uses: actions/cache@v2
166+
with:
167+
path: ${{ steps.pip-cache.outputs.dir }}
168+
key:
169+
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/tox.ini') }}
170+
restore-keys: |
171+
${{ matrix.python-version }}-v1-
172+
173+
- name: Install dependencies
174+
run: |
175+
python -m pip install --upgrade pip
176+
python -m pip install --upgrade tox tox-gh-actions
177+
178+
- name: Test with tox
179+
run: tox
180+
env:
181+
DB_BACKEND: sqlite3
182+
DB_NAME: ":memory:"
183+
184+
- name: Upload coverage
185+
uses: codecov/codecov-action@v1
186+
with:
187+
name: Python ${{ matrix.python-version }}
188+
189+
lint:
190+
runs-on: ubuntu-latest
191+
strategy:
192+
fail-fast: false
193+
194+
steps:
195+
- uses: actions/checkout@v2
196+
197+
- name: Set up Python ${{ matrix.python-version }}
198+
uses: actions/setup-python@v2
199+
with:
200+
python-version: 3.8
201+
202+
- name: Get pip cache dir
203+
id: pip-cache
204+
run: |
205+
echo "::set-output name=dir::$(pip cache dir)"
206+
207+
- name: Cache
208+
uses: actions/cache@v2
209+
with:
210+
path: ${{ steps.pip-cache.outputs.dir }}
211+
key:
212+
${{ matrix.python-version }}-v1-${{ hashFiles('**/setup.cfg') }}-${{ hashFiles('**/tox.ini') }}
213+
restore-keys: |
214+
${{ matrix.python-version }}-v1-
215+
216+
- name: Install dependencies
217+
run: |
218+
python -m pip install --upgrade pip
219+
python -m pip install --upgrade tox
220+
221+
- name: Test with tox
222+
run: tox -e docs,style,readme

example/README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Run the Django development server::
4141

4242
$ python example/manage.py runserver
4343

44-
You can change the database used by specifying the ``DJANGO_DATABASE_ENGINE``
44+
You can change the database used by specifying the ``DB_BACKEND``
4545
environment variable::
4646

47-
$ DJANGO_DATABASE_ENGINE=postgresql python example/manage.py migrate
48-
$ DJANGO_DATABASE_ENGINE=postgresql python example/manage.py runserver
47+
$ DB_BACKEND=postgresql python example/manage.py migrate
48+
$ DB_BACKEND=postgresql python example/manage.py runserver

example/settings.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
}
7272
}
7373

74-
# To use another database, set the DJANGO_DATABASE_ENGINE environment variable.
75-
if os.environ.get("DJANGO_DATABASE_ENGINE", "").lower() == "postgresql":
74+
# To use another database, set the DB_BACKEND environment variable.
75+
if os.environ.get("DB_BACKEND", "").lower() == "postgresql":
7676
# % su postgres
7777
# % createuser debug_toolbar
7878
# % createdb debug_toolbar -O debug_toolbar
@@ -83,7 +83,7 @@
8383
"USER": "debug_toolbar",
8484
}
8585
}
86-
if os.environ.get("DJANGO_DATABASE_ENGINE", "").lower() == "mysql":
86+
if os.environ.get("DB_BACKEND", "").lower() == "mysql":
8787
# % mysql
8888
# mysql> CREATE DATABASE debug_toolbar;
8989
# mysql> CREATE USER 'debug_toolbar'@'localhost';

tests/settings.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -79,31 +79,19 @@
7979
"second": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"},
8080
}
8181

82-
if os.environ.get("DJANGO_DATABASE_ENGINE") == "postgresql":
83-
DATABASES = {
84-
"default": {
85-
"ENGINE": "django.db.backends.postgresql",
86-
"NAME": "debug_toolbar",
87-
"USER": "postgres",
88-
"PASSWORD": "postgres",
89-
"HOST": "localhost",
90-
"PORT": os.environ.get("POSTGRES_PORT", ""),
91-
}
92-
}
93-
elif os.environ.get("DJANGO_DATABASE_ENGINE") == "mysql":
94-
DATABASES = {
95-
"default": {
96-
"ENGINE": "django.db.backends.mysql",
97-
"NAME": "debug_toolbar",
98-
"USER": "root",
99-
"PASSWORD": "debug_toolbar",
100-
"HOST": "127.0.0.1",
101-
"PORT": os.environ.get("MYSQL_PORT", ""),
102-
}
103-
}
104-
else:
105-
DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3"}}
106-
82+
DATABASES = {
83+
"default": {
84+
"ENGINE": "django.db.backends.%s" % os.getenv("DB_BACKEND"),
85+
"NAME": os.getenv("DB_NAME"),
86+
"USER": os.getenv("DB_USER"),
87+
"PASSWORD": os.getenv("DB_PASSWORD"),
88+
"HOST": os.getenv("DB_HOST", ""),
89+
"PORT": os.getenv("DB_PORT", ""),
90+
"TEST": {
91+
"USER": "default_test",
92+
},
93+
},
94+
}
10795

10896
# Debug Toolbar configuration
10997

tox.ini

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[tox]
22
envlist =
3-
py38-docs
4-
py38-style
5-
py38-readme
3+
docs
4+
style
5+
readme
66
py{36,37,38}-dj22-sqlite
77
py{36,37,38}-dj{30,31}-sqlite
88
py{36,37,38}-djmaster-sqlite
9-
py{37,38}-dj{22,30,31}-{postgresql,mariadb}
9+
py{37,38}-dj{22,30,31}-{postgresql,mysql}
1010

1111
[testenv]
1212
deps =
@@ -15,7 +15,7 @@ deps =
1515
dj31: Django==3.1.*
1616
sqlite: mock
1717
postgresql: psycopg2-binary
18-
mariadb: mysqlclient
18+
mysql: mysqlclient
1919
djmaster: https://github.com/django/django/archive/master.tar.gz
2020
coverage
2121
Jinja2
@@ -24,33 +24,36 @@ deps =
2424
sqlparse
2525
passenv=
2626
CI
27-
MYSQL_PORT
28-
POSTGRES_PORT
27+
DB_BACKEND
28+
DB_NAME
29+
DB_USER
30+
DB_PASSWORD
31+
DB_HOST
32+
DB_PORT
33+
GITHUB_*
2934
setenv =
3035
PYTHONPATH = {toxinidir}
3136
PYTHONWARNINGS = d
32-
postgresql: DJANGO_DATABASE_ENGINE = postgresql
3337
py38-dj31-postgresql: DJANGO_SELENIUM_TESTS = true
34-
mariadb: DJANGO_DATABASE_ENGINE = mysql
3538
whitelist_externals = make
3639
pip_pre = True
3740
commands = make coverage TEST_ARGS='{posargs:tests}'
3841

39-
[testenv:py38-docs]
42+
[testenv:docs]
4043
commands = make -C {toxinidir}/docs spelling
4144
deps =
4245
Sphinx
4346
sphinxcontrib-spelling
4447

45-
[testenv:py38-style]
48+
[testenv:style]
4649
commands = make style_check
4750
deps =
4851
black>=19.10b0
4952
flake8
5053
isort>=5.0.2
5154
skip_install = true
5255

53-
[testenv:py38-readme]
56+
[testenv:readme]
5457
commands = python setup.py check -r -s
5558
deps = readme_renderer
5659
skip_install = true
@@ -60,3 +63,9 @@ python =
6063
3.6: py36
6164
3.7: py37
6265
3.8: py38
66+
67+
[gh-actions:env]
68+
DB_BACKEND =
69+
mysql: mysql
70+
postgresql: postgresql
71+
sqlite3: sqlite

0 commit comments

Comments
 (0)