Возможно, вы захотите иметь pytest
в качестве тестового бегуна.Ниже приведен пример конфигурации.
Образец pytest.ini
файл:
[pytest]
norecursedirs=
*.egg
.git
.tox
.env
_sass
build
dist
migrations
fabfile
.tox
python_files =
test_*.py
tests.py
DJANGO_SETTINGS_MODULE=settings.dev
addopts=
--reuse-db
--nomigrations
--cov=your_app
--ignore=.tox
--ignore=fabfile
--ignore=scripts
--ignore=settings
--ignore=tmp
--cov-report=html
--cov-report=term
--cov-report=annotate
Образец runtests.py
Файл:
#!/usr/bin/env python
import os
import sys
import pytest
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings.dev")
return pytest.main()
if __name__ == '__main__':
sys.exit(main())
Образец requirements.txt
Файл:
pytest==3.0.2
pytest-django==2.9.1
pytest-cov==2.2.1
Запустите тесты:
./runtests.py
Обратите внимание, что эффект достигается с помощью директив reuse-db
и nomigrations
.