From c922e38152193997f07752ec5191a7d6de91a0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20K=C3=B6gl?= Date: Sun, 26 Nov 2017 22:31:02 +0100 Subject: [PATCH] Switch to py.test --- .gitignore | 2 ++ gunicorn.conf.py => conf/gunicorn.conf.py | 0 conftest.py | 9 +++++++++ makefile | 4 ++-- mygpo/settings.py | 9 --------- mygpo/users/tests.py | 4 ++-- mygpo/usersettings/tests.py | 4 ++-- pytest.ini | 5 +++++ requirements-test.txt | 4 ++-- 9 files changed, 24 insertions(+), 17 deletions(-) rename gunicorn.conf.py => conf/gunicorn.conf.py (100%) create mode 100644 conftest.py create mode 100644 pytest.ini diff --git a/.gitignore b/.gitignore index 90608c9eb..00fe485e3 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ envs # Jupyter Notebooks notebooks/ + +.cache diff --git a/gunicorn.conf.py b/conf/gunicorn.conf.py similarity index 100% rename from gunicorn.conf.py rename to conf/gunicorn.conf.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..61629a16d --- /dev/null +++ b/conftest.py @@ -0,0 +1,9 @@ +import pytest + + +@pytest.fixture(autouse=True) +def enable_db_access_for_all_tests(db): + """ Enable DB access for all tests + + http://pytest-django.readthedocs.io/en/latest/faq.html#how-can-i-give-database-access-to-all-my-tests-without-the-django-db-marker """ + pass diff --git a/makefile b/makefile index 3c4e140a3..852771ecd 100644 --- a/makefile +++ b/makefile @@ -5,8 +5,8 @@ help: @echo 'make clean clean up files' test: - envdir envs/dev/ python -Wd -m coverage run ./manage.py test - coverage report + envdir envs/dev/ pytest --cov=mygpo/ --cov-branch + coverage report --show-missing update-po: envdir envs/dev/ python manage.py makemessages \ diff --git a/mygpo/settings.py b/mygpo/settings.py index 5e77fb955..97b5d8222 100644 --- a/mygpo/settings.py +++ b/mygpo/settings.py @@ -158,7 +158,6 @@ def get_intOrNone(name, default): 'mygpo.pubsub', 'mygpo.podcastlists', 'mygpo.votes', - 'django_nose', ] try: @@ -373,13 +372,5 @@ def get_intOrNone(name, default): PODCAST_AD_ID = os.getenv('PODCAST_AD_ID') -TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' - -NOSE_ARGS = [ - '--with-doctest', - '--stop', - '--where=mygpo', -] - SEARCH_CUTOFF = float(os.getenv('SEARCH_CUTOFF', 0.3)) diff --git a/mygpo/users/tests.py b/mygpo/users/tests.py index 5f65b7b49..5c6800020 100644 --- a/mygpo/users/tests.py +++ b/mygpo/users/tests.py @@ -3,7 +3,7 @@ from collections import Counter from django.urls import reverse -from django.test.client import Client as TestClient +from django.test.client import Client as TClient from django.test import TestCase from django.test.utils import override_settings from django.contrib.auth import get_user_model @@ -100,7 +100,7 @@ class AuthTests(TestCase): def setUp(self): self.user, pwd = create_user() - self.client = TestClient() + self.client = TClient() wrong_pwd = pwd + '1234' self.extra = { 'HTTP_AUTHORIZATION': create_auth_string(self.user.username, diff --git a/mygpo/usersettings/tests.py b/mygpo/usersettings/tests.py index dda1d4be6..0ed32e749 100644 --- a/mygpo/usersettings/tests.py +++ b/mygpo/usersettings/tests.py @@ -5,7 +5,7 @@ import json from django.urls import reverse -from django.test.client import Client as TestClient +from django.test.client import Client as TClient from django.test import TestCase from mygpo.test import create_auth_string, create_user @@ -32,7 +32,7 @@ def setUp(self): user = self.user, uid = self.uid, ) - self.client = TestClient() + self.client = TClient() self.extra = { 'HTTP_AUTHORIZATION': create_auth_string(self.user.username, pwd) } diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..799cee2a2 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +DJANGO_SETTINGS_MODULE = mygpo.settings +python_files = tests.py test_*.py *_tests.py +addopts = --doctest-modules +norecursedirs = tools conf diff --git a/requirements-test.txt b/requirements-test.txt index e103fffea..5936206b8 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,5 +1,5 @@ coverage==4.4.1 django-coverage-plugin==1.5.0 -django-nose==1.4.5 -nose==1.3.7 +pytest-django +pytest-cov responses==0.8.1