From abda11246733c9a1f0c7bac76ee63e75081a4489 Mon Sep 17 00:00:00 2001 From: Valentin Samir Date: Wed, 29 Jun 2016 08:22:52 +0200 Subject: [PATCH] Begin to split tests, Makefile less phony, use py.test --- .coveragerc | 5 ++++ Makefile | 26 ++++++++++++------- cas_server/tests/__init__.py | 0 .../tests/settings.py | 3 ++- cas_server/{tests.py => tests/test_view.py} | 2 +- urls_tests.py => cas_server/tests/urls.py | 0 pytest.ini | 5 ++++ requirements-dev.txt | 11 ++++---- run_tests | 22 ---------------- setup.py | 3 ++- tox.ini | 2 +- 11 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 cas_server/tests/__init__.py rename settings_tests.py => cas_server/tests/settings.py (96%) rename cas_server/{tests.py => tests/test_view.py} (99%) rename urls_tests.py => cas_server/tests/urls.py (100%) create mode 100644 pytest.ini delete mode 100755 run_tests diff --git a/.coveragerc b/.coveragerc index b4da6da..abcfd58 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,3 +1,8 @@ +[run] +branch = True +source = cas_server +omit = cas_server/migrations* + [report] exclude_lines = pragma: no cover diff --git a/Makefile b/Makefile index 2273da9..627a5c0 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: clean build install dist test_venv test_project +.PHONY: build dist VERSION=`python setup.py -V` build: @@ -16,18 +16,19 @@ clean_tox: rm -rf .tox clean_test_venv: rm -rf test_venv + clean: clean_pyc clean_build + clean_all: clean_pyc clean_build clean_tox clean_test_venv dist: python setup.py sdist -test_venv: - mkdir -p test_venv +test_venv/bin/python: virtualenv test_venv - test_venv/bin/pip install -U --requirement requirements.txt + test_venv/bin/pip install -U --requirement requirements-dev.txt Django -test_venv/cas/manage.py: +test_venv/cas/manage.py: test_venv mkdir -p test_venv/cas test_venv/bin/django-admin startproject cas test_venv/cas ln -s ../../cas_server test_venv/cas/cas_server @@ -38,16 +39,23 @@ test_venv/cas/manage.py: test_venv/bin/python test_venv/cas/manage.py migrate test_venv/bin/python test_venv/cas/manage.py createsuperuser -test_project: test_venv test_venv/cas/manage.py +test_venv/bin/coverage: test_venv + test_venv/bin/pip install coverage + +test_venv: test_venv/bin/python + +test_project: test_venv/cas/manage.py @echo "##############################################################" @echo "A test django project was created in $(realpath test_venv/cas)" run_test_server: test_project test_venv/bin/python test_venv/cas/manage.py runserver -coverage: test_venv - test_venv/bin/pip install coverage - test_venv/bin/coverage run --source='cas_server' --omit='cas_server/migrations*' run_tests +tests: test_venv + test_venv/bin/py.test + +coverage: test_venv/bin/coverage + test_venv/bin/coverage run test_venv/bin/py.test test_venv/bin/coverage html rm htmlcov/coverage_html.js # I am really pissed off by those keybord shortcuts diff --git a/cas_server/tests/__init__.py b/cas_server/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/settings_tests.py b/cas_server/tests/settings.py similarity index 96% rename from settings_tests.py rename to cas_server/tests/settings.py index e1c0558..1402c64 100644 --- a/settings_tests.py +++ b/cas_server/tests/settings.py @@ -52,7 +52,7 @@ MIDDLEWARE_CLASSES = [ 'django.middleware.locale.LocaleMiddleware', ] -ROOT_URLCONF = 'urls_tests' +ROOT_URLCONF = 'cas_server.tests.urls' # Database # https://docs.djangoproject.com/en/1.9/ref/settings/#databases @@ -60,6 +60,7 @@ ROOT_URLCONF = 'urls_tests' DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', } } diff --git a/cas_server/tests.py b/cas_server/tests/test_view.py similarity index 99% rename from cas_server/tests.py rename to cas_server/tests/test_view.py index a12feab..72185a6 100644 --- a/cas_server/tests.py +++ b/cas_server/tests/test_view.py @@ -1,5 +1,5 @@ """Tests module""" -from .default_settings import settings +from cas_server.default_settings import settings import django from django.test import TestCase, Client diff --git a/urls_tests.py b/cas_server/tests/urls.py similarity index 100% rename from urls_tests.py rename to cas_server/tests/urls.py diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..74acafe --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +testpaths = cas_server/tests/ +DJANGO_SETTINGS_MODULE = cas_server.tests.settings +norecursedirs = .* build dist docs +python_paths = . diff --git a/requirements-dev.txt b/requirements-dev.txt index e6ef993..b6bc994 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,10 +1,11 @@ -tox==1.8.1 -pytest==2.6.4 -pytest-django==2.7.0 -pytest-pythonpath==0.3 +setuptools>=5.5 +tox>=1.8.1 +pytest>=2.6.4 +pytest-django>=2.8.0 +pytest-pythonpath>=0.3 requests>=2.4 -django-picklefield>=0.3.1 requests_futures>=0.9.5 +django-picklefield>=0.3.1 django-bootstrap3>=5.4 lxml>=3.4 six>=1 diff --git a/run_tests b/run_tests deleted file mode 100755 index 4ea21ee..0000000 --- a/run_tests +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env python -import os, sys -import django -from django.conf import settings - -import settings_tests - -settings.configure(**settings_tests.__dict__) -django.setup() - -try: - # Django <= 1.8 - from django.test.simple import DjangoTestSuiteRunner - test_runner = DjangoTestSuiteRunner(verbosity=1) -except ImportError: - # Django >= 1.8 - from django.test.runner import DiscoverRunner - test_runner = DiscoverRunner(verbosity=1) - -failures = test_runner.run_tests(['cas_server']) -if failures: - sys.exit(failures) diff --git a/setup.py b/setup.py index a9826c7..0548d66 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,8 @@ setup( version='0.4.4', packages=[ 'cas_server', 'cas_server.migrations', - 'cas_server.management', 'cas_server.management.commands' + 'cas_server.management', 'cas_server.management.commands', + 'cas_server.tests' ], include_package_data=True, license='GPLv3', diff --git a/tox.ini b/tox.ini index 0b65c56..3e876df 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,7 @@ deps = -r{toxinidir}/requirements-dev.txt [testenv] -commands=python run_tests {posargs:tests} +commands=py.test {posargs:cas_server/tests/} [testenv:py27-django17] basepython=python2.7