Skip to content

Commit 0288e9f

Browse files
author
Ryan P Kilby
committed
Move isort/lint commands out of test runner
1 parent 657ff2b commit 0288e9f

File tree

3 files changed

+9
-53
lines changed

3 files changed

+9
-53
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ matrix:
2020
- { python: "3.6", env: DJANGO=master }
2121
- { python: "3.6", env: DJANGO=1.11 }
2222
- { python: "3.6", env: DJANGO=2.0 }
23-
- { python: "2.7", env: TOXENV=lint }
23+
- { python: "3.6", env: TOXENV="isort,lint" }
2424
- { python: "2.7", env: TOXENV=docs }
2525

2626
- python: "3.6"

runtests.py

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#! /usr/bin/env python
22
from __future__ import print_function
33

4-
import subprocess
54
import sys
65

76
import pytest
@@ -11,35 +10,12 @@
1110
'fast': ['tests', '--tb=short', '-q', '-s', '-rw'],
1211
}
1312

14-
FLAKE8_ARGS = ['rest_framework', 'tests']
15-
16-
ISORT_ARGS = ['--recursive', '--check-only', '-o' 'uritemplate', '-p', 'tests', 'rest_framework', 'tests']
17-
1813

1914
def exit_on_failure(ret, message=None):
2015
if ret:
2116
sys.exit(ret)
2217

2318

24-
def flake8_main(args):
25-
print('Running flake8 code linting')
26-
ret = subprocess.call(['flake8'] + args)
27-
print('flake8 failed' if ret else 'flake8 passed')
28-
return ret
29-
30-
31-
def isort_main(args):
32-
print('Running isort code checking')
33-
ret = subprocess.call(['isort'] + args)
34-
35-
if ret:
36-
print('isort failed: Some modules have incorrectly ordered imports. Fix by running `isort --recursive .`')
37-
else:
38-
print('isort passed')
39-
40-
return ret
41-
42-
4319
def split_class_and_function(string):
4420
class_string, function_string = string.split('.', 1)
4521
return "%s and %s" % (class_string, function_string)
@@ -56,22 +32,6 @@ def is_class(string):
5632

5733

5834
if __name__ == "__main__":
59-
try:
60-
sys.argv.remove('--nolint')
61-
except ValueError:
62-
run_flake8 = True
63-
run_isort = True
64-
else:
65-
run_flake8 = False
66-
run_isort = False
67-
68-
try:
69-
sys.argv.remove('--lintonly')
70-
except ValueError:
71-
run_tests = True
72-
else:
73-
run_tests = False
74-
7535
try:
7636
sys.argv.remove('--fast')
7737
except ValueError:
@@ -110,11 +70,4 @@ def is_class(string):
11070
else:
11171
pytest_args = PYTEST_ARGS[style]
11272

113-
if run_tests:
114-
exit_on_failure(pytest.main(pytest_args))
115-
116-
if run_flake8:
117-
exit_on_failure(flake8_main(FLAKE8_ARGS))
118-
119-
if run_isort:
120-
exit_on_failure(isort_main(ISORT_ARGS))
73+
exit_on_failure(pytest.main(pytest_args))

tox.ini

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ deps =
3737
-rrequirements/requirements-testing.txt
3838
-rrequirements/requirements-optionals.txt
3939

40+
[testenv:isort]
41+
commands = isort --recursive --check-only rest_framework tests {posargs}
42+
deps =
43+
-rrequirements/requirements-codestyle.txt
44+
4045
[testenv:lint]
41-
basepython = python2.7
42-
commands = ./runtests.py --lintonly
46+
commands = flake8 rest_framework tests {posargs}
4347
deps =
44-
-rrequirements/requirements-codestyle.txt
45-
-rrequirements/requirements-testing.txt
48+
-rrequirements/requirements-codestyle.txt
4649

4750
[testenv:docs]
4851
basepython = python2.7

0 commit comments

Comments
 (0)