From 4a73df255fff96660ccff03368703e5d67a27651 Mon Sep 17 00:00:00 2001 From: Silvano Cerza Date: Sun, 12 Feb 2017 16:22:46 +0100 Subject: [PATCH] Started migrating to pytest --- .gitignore | 1 + requirements-test.txt | 6 ++++-- runtests.py | 47 ++----------------------------------------- tests/settings.py | 29 ++++++++++++++++++++++++++ tox.ini | 6 +++++- 5 files changed, 41 insertions(+), 48 deletions(-) create mode 100644 tests/settings.py diff --git a/.gitignore b/.gitignore index 3990762..ec60d0e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ lib64 pip-log.txt # Unit test / coverage reports +.cache .coverage .tox nosetests.xml diff --git a/requirements-test.txt b/requirements-test.txt index 8cd3779..588321c 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1,6 +1,8 @@ py-moneyed==0.6.0 mock>=1.0.1 -nose>=1.3.0 -django-nose>=1.2 +pytest-mock==1.2 +pytest==2.9.2 +pytest-django==3.1.2 + # Additional test requirements go here diff --git a/runtests.py b/runtests.py index 378d1e0..b192066 100644 --- a/runtests.py +++ b/runtests.py @@ -1,47 +1,4 @@ import sys -from optparse import OptionParser +import pytest -try: - from django.conf import settings - - settings.configure( - DEBUG=True, - USE_TZ=True, - DATABASES={ - "default": { - "ENGINE": "django.db.backends.sqlite3", - } - }, - ROOT_URLCONF="djmoney_rates.urls", - INSTALLED_APPS=[ - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sites", - "djmoney_rates", - ], - SITE_ID=1, - NOSE_ARGS=['-s'], - ) - - from django_nose import NoseTestSuiteRunner -except ImportError: - raise ImportError("To fix this error, run: pip install -r requirements-test.txt") - - -def run_tests(*test_args): - if not test_args: - test_args = ['tests'] - - # Run tests - test_runner = NoseTestSuiteRunner(verbosity=1) - - failures = test_runner.run_tests(test_args) - - if failures: - sys.exit(failures) - - -if __name__ == '__main__': - parser = OptionParser() - (options, args) = parser.parse_args() - run_tests(*args) \ No newline at end of file +sys.exit(pytest.main()) \ No newline at end of file diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..a1445a3 --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,29 @@ +USE_TZ = True + +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": "example.sqlite", + } +} + +ROOT_URLCONF = "djmoney_rates.urls" + +INSTALLED_APPS = [ + "django.contrib.auth", + "django.contrib.contenttypes", + "django.contrib.sites", + "djmoney_rates", +] + +SECRET_KEY = "1234567890evonove" + +TEMPLATES = [ + { + 'OPTIONS': { + 'debug': True, + } + } +] + +SITE_ID = 1 diff --git a/tox.ini b/tox.ini index 7fd62e5..5ec588e 100644 --- a/tox.ini +++ b/tox.ini @@ -1,3 +1,7 @@ +[pytest] +DJANGO_SETTINGS_MODULE=tests.settings +testpaths=tests + [tox] envlist = py27-django{18,19,110,master}, @@ -19,7 +23,7 @@ deps = setenv = PYTHONPATH = {toxinidir}:{toxinidir}/djmoney_rates commands = - coverage run -a runtests.py + python runtests.py [testenv:flake8] deps =