$ tree project/settings
project/settings
├── __init__.py
├── base.py
├── local.py
├── production.py
└── test.py
$ python manage.py test --settings project.settings.test
$ pytest --ds project.settings.test
$ cat pytest.init
[pytest]
DJANGO_SETTINGS_MODULE = config.settings.test
$ cat project/settings/test.py
from .base import *
DJANGO_DEBUG = False
PASSWORD_HASHERS = [
"django.contrib.auth.hashers.MD5PasswordHasher",
]
DEFAULT_FILE_STORAGE = "inmemorystorage.InMemoryStorage"
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend"
CACHES = {
"default": {"BACKEND": "django.core.cache.backends.locmem.LocMemCache"}
}
CELERY_ALWAYS_EAGER = True
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
$ python manage.py test --parallel
$ py.test --n auto
TestCase 1
TestCase 2
TestCase 3
TestCase 4
TestCase 1
TestCase 2
TestCase 3
TestCase 4
TestCase 1
Ready
TestCase 3
TestCase 4
TestCase 1
Ready
Ready
Ready
TestCase 1
Ready
TestCase 3
TestCase 4
TestCase 1
Ready
TestCase 3
TestCase 4
py.test --nomigrations
py.test --keepdb
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.6.10
uses: actions/setup-python@v1
with:
python-version: 3.6.10
- name: Cache pip
uses: actions/cache@v1
with:
path: /opt/hostedtoolcache/Python/3.6.10/x64/ # This path is specific to Ubuntu
# If the requirements files change, the cache will not hit.
key: python-${{ hashFiles('requirements/local.txt') }}-${{ hashFiles('requirements/base.txt') }}
GitHub Action Example
Don't cache ~/.cache/pip
$ docker run \
--mount type=tmpfs,destination=/var/lib/postgresql/data \
--detach \
If build is still slow get more hardware
💰