Skip to content

Commit 971578c

Browse files
committed
Support for running the test suite with py.test
* Get rid of runtests.py * Moved test code from rest_framework/tests and rest_framework/runtests to tests * Invoke py.test from setup.py * Invoke py.test from Travis * Invoke py.test from tox * Changed setUpClass to be just plain setUp in test_permissions.py * Updated contribution guideline to show how to invoke py.test
1 parent 62786a7 commit 971578c

Some content is hidden

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

73 files changed

+206
-251
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ env:
1515
install:
1616
- pip install $DJANGO
1717
- pip install defusedxml==0.3
18+
- pip install pytest-django==2.6
1819
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install oauth2==1.5.211; fi"
1920
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth-plus==2.2.1; fi"
2021
- "if [[ ${TRAVIS_PYTHON_VERSION::1} != '3' ]]; then pip install django-oauth2-provider==0.2.4; fi"
@@ -24,7 +25,7 @@ install:
2425
- export PYTHONPATH=.
2526

2627
script:
27-
- python rest_framework/runtests/runtests.py
28+
- py.test
2829

2930
matrix:
3031
exclude:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
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

conftest.py

Lines changed: 85 additions & 0 deletions
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()

docs/index.md

Lines changed: 3 additions & 13 deletions
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

docs/topics/contributing.md

Lines changed: 1 addition & 1 deletion
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

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
addopts = --tb=short

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
-e .
12
Django>=1.3
3+
pytest-django==2.6

rest_framework/runtests/runcoverage.py

Lines changed: 0 additions & 78 deletions
This file was deleted.

rest_framework/runtests/runtests.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

rest_framework/runtests/urls.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)