Skip to content

Commit 1797a74

Browse files
committed
Merge remote-tracking branch 'pelme/pytest' into feature/pytest
Conflicts: .travis.yml rest_framework/runtests/runtests.py tests/test_filters.py tests/test_pagination.py tox.ini
2 parents 1d40487 + 971578c commit 1797a74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+205
-256
lines changed

Diff for: .travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ env:
1616
install:
1717
- pip install $DJANGO
1818
- pip install defusedxml==0.3 Pillow==2.3.0
19+
- pip install pytest-django==2.6
1920
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install oauth2==1.5.211; fi"
2021
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth-plus==2.2.4; fi"
2122
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth2-provider==0.2.4; fi"
@@ -27,7 +28,7 @@ install:
2728
- export PYTHONPATH=.
2829

2930
script:
30-
- python rest_framework/runtests/runtests.py
31+
- py.test
3132

3233
matrix:
3334
exclude:

Diff for: CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ To run the tests, clone the repository, and then:
6565
pip install -r optionals.txt
6666

6767
# Run the tests
68-
rest_framework/runtests/runtests.py
68+
py.test
6969

7070
You can also use the excellent [`tox`][tox] testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run:
7171

Diff for: conftest.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
def pytest_configure():
2+
from django.conf import settings
3+
4+
settings.configure(
5+
DEBUG_PROPAGATE_EXCEPTIONS=True,
6+
DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3',
7+
'NAME': ':memory:'}},
8+
SECRET_KEY='not very secret in tests',
9+
USE_I18N=True,
10+
USE_L10N=True,
11+
STATIC_URL='/static/',
12+
ROOT_URLCONF='tests.urls',
13+
TEMPLATE_LOADERS=(
14+
'django.template.loaders.filesystem.Loader',
15+
'django.template.loaders.app_directories.Loader',
16+
),
17+
MIDDLEWARE_CLASSES=(
18+
'django.middleware.common.CommonMiddleware',
19+
'django.contrib.sessions.middleware.SessionMiddleware',
20+
'django.middleware.csrf.CsrfViewMiddleware',
21+
'django.contrib.auth.middleware.AuthenticationMiddleware',
22+
'django.contrib.messages.middleware.MessageMiddleware',
23+
),
24+
INSTALLED_APPS=(
25+
'django.contrib.auth',
26+
'django.contrib.contenttypes',
27+
'django.contrib.sessions',
28+
'django.contrib.sites',
29+
'django.contrib.messages',
30+
31+
'rest_framework',
32+
'rest_framework.authtoken',
33+
'tests',
34+
'tests.accounts',
35+
'tests.records',
36+
'tests.users',
37+
),
38+
PASSWORD_HASHERS=(
39+
'django.contrib.auth.hashers.SHA1PasswordHasher',
40+
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
41+
'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
42+
'django.contrib.auth.hashers.BCryptPasswordHasher',
43+
'django.contrib.auth.hashers.MD5PasswordHasher',
44+
'django.contrib.auth.hashers.CryptPasswordHasher',
45+
),
46+
)
47+
48+
try:
49+
import oauth_provider
50+
import oauth2
51+
except ImportError:
52+
pass
53+
else:
54+
settings.INSTALLED_APPS += (
55+
'oauth_provider',
56+
)
57+
58+
try:
59+
import provider
60+
except ImportError:
61+
pass
62+
else:
63+
settings.INSTALLED_APPS += (
64+
'provider',
65+
'provider.oauth2',
66+
)
67+
68+
# guardian is optional
69+
try:
70+
import guardian
71+
except ImportError:
72+
pass
73+
else:
74+
settings.ANONYMOUS_USER_ID = -1
75+
settings.AUTHENTICATION_BACKENDS = (
76+
'django.contrib.auth.backends.ModelBackend', # default
77+
'guardian.backends.ObjectPermissionBackend',
78+
)
79+
settings.INSTALLED_APPS += (
80+
'guardian',
81+
)
82+
83+
# Force Django to load all models
84+
from django.db.models import get_models
85+
get_models()

Diff for: docs/index.md

+3-13
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,9 @@ General guides to using REST framework.
206206

207207
## Development
208208

209-
If you want to work on REST framework itself, clone the repository, then...
210-
211-
Build the docs:
212-
213-
./mkdocs.py
214-
215-
Run the tests:
216-
217-
./rest_framework/runtests/runtests.py
218-
219-
To run the tests against all supported configurations, first install [the tox testing tool][tox] globally, using `pip install tox`, then simply run `tox`:
220-
221-
tox
209+
See the [Contribution guidelines][contributing] for information on how to clone
210+
the repository, run the test suite and contribute changes back to REST
211+
Framework.
222212

223213
## Support
224214

Diff for: docs/topics/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ To run the tests, clone the repository, and then:
6565
pip install -r optionals.txt
6666

6767
# Run the tests
68-
rest_framework/runtests/runtests.py
68+
py.test
6969

7070
You can also use the excellent [tox][tox] testing tool to run the tests against all supported versions of Python and Django. Install `tox` globally, and then simply run:
7171

Diff for: pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --tb=short

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
-e .
12
Django>=1.3
3+
pytest-django==2.6

Diff for: rest_framework/runtests/runcoverage.py

-78
This file was deleted.

Diff for: rest_framework/runtests/runtests.py

-52
This file was deleted.

Diff for: rest_framework/runtests/urls.py

-7
This file was deleted.

Diff for: rest_framework/tests/tests.py

-16
This file was deleted.

Diff for: rest_framework/tests/users/__init__.py

Whitespace-only changes.

Diff for: setup.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,26 @@
22
# -*- coding: utf-8 -*-
33

44
from setuptools import setup
5+
from setuptools.command.test import test as TestCommand
56
import re
67
import os
78
import sys
89

910

11+
# This command has been borrowed from
12+
# https://github.com/getsentry/sentry/blob/master/setup.py
13+
class PyTest(TestCommand):
14+
def finalize_options(self):
15+
TestCommand.finalize_options(self)
16+
self.test_args = ['tests']
17+
self.test_suite = True
18+
19+
def run_tests(self):
20+
import pytest
21+
errno = pytest.main(self.test_args)
22+
sys.exit(errno)
23+
24+
1025
def get_version(package):
1126
"""
1227
Return package version as listed in `__version__` in `init.py`.
@@ -62,7 +77,7 @@ def get_package_data(package):
6277
author_email='tom@tomchristie.com', # SEE NOTE BELOW (*)
6378
packages=get_packages('rest_framework'),
6479
package_data=get_package_data('rest_framework'),
65-
test_suite='rest_framework.runtests.runtests.main',
80+
cmdclass={'test': PyTest},
6681
install_requires=[],
6782
classifiers=[
6883
'Development Status :: 5 - Production/Stable',
File renamed without changes.
File renamed without changes.

Diff for: rest_framework/tests/accounts/models.py renamed to tests/accounts/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from django.db import models
22

3-
from rest_framework.tests.users.models import User
3+
from tests.users.models import User
44

55

66
class Account(models.Model):

Diff for: rest_framework/tests/accounts/serializers.py renamed to tests/accounts/serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from rest_framework import serializers
22

3-
from rest_framework.tests.accounts.models import Account
4-
from rest_framework.tests.users.serializers import UserSerializer
3+
from tests.accounts.models import Account
4+
from tests.users.serializers import UserSerializer
55

66

77
class AccountSerializer(serializers.ModelSerializer):
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: rest_framework/tests/serializers.py renamed to tests/serializers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from rest_framework import serializers
22

3-
from rest_framework.tests.models import NullableForeignKeySource
3+
from tests.models import NullableForeignKeySource
44

55

66
class NullableFKSourceSerializer(serializers.ModelSerializer):

Diff for: rest_framework/runtests/settings.py renamed to tests/settings.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
'django.contrib.messages.middleware.MessageMiddleware',
8080
)
8181

82-
ROOT_URLCONF = 'urls'
82+
ROOT_URLCONF = 'tests.urls'
8383

8484
TEMPLATE_DIRS = (
8585
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
@@ -99,10 +99,10 @@
9999
# 'django.contrib.admindocs',
100100
'rest_framework',
101101
'rest_framework.authtoken',
102-
'rest_framework.tests',
103-
'rest_framework.tests.accounts',
104-
'rest_framework.tests.records',
105-
'rest_framework.tests.users',
102+
'tests',
103+
'tests.accounts',
104+
'tests.records',
105+
'tests.users',
106106
)
107107

108108
# OAuth is optional and won't work if there is no oauth_provider & oauth2

0 commit comments

Comments
 (0)