Skip to content

Commit ccc4b3a

Browse files
Merge pull request #2596 from nicoddemus/autopep-tox
Add "fix-lint" tox environment
2 parents da12c52 + 3c28a8e commit ccc4b3a

15 files changed

+74
-49
lines changed

CONTRIBUTING.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,12 @@ but here is a simple overview:
212212
$ tox -e linting,py27,py36
213213

214214
This command will run tests via the "tox" tool against Python 2.7 and 3.6
215-
and also perform "lint" coding-style checks.
215+
and also perform "lint" coding-style checks. If you have too much linting errors,
216+
try running::
217+
218+
$ tox -e fix-lint
219+
220+
To fix pep8 related errors.
216221

217222
#. You can now edit your local working copy.
218223

changelog/2375.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add missing ``encoding`` attribute to ``sys.std*`` streams when using ``capsys`` capture mode.

changelog/2375.trivial

Lines changed: 0 additions & 1 deletion
This file was deleted.

changelog/2533.trivial

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Renamed the utility function `_pytest.compat._escape_strings` to `_ascii_escaped` to better communicate the function's purpose.
1+
Renamed the utility function ``_pytest.compat._escape_strings`` to ``_ascii_escaped`` to better communicate the function's purpose.

changelog/2562.trivial

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Emit yield test warning only once per generator
1+
Emit warning about ``yield`` tests being deprecated only once per generator.

changelog/2574.bugfix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
The options --fixtures and --fixtures-per-test will now keep indentation within docstrings.
1+
The options ```--fixtures`` and ```--fixtures-per-test`` will now keep indentation within docstrings.

changelog/2581.trivial

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Fixed all flake8 errors and warnings
1+
Fixed all flake8 errors and warnings.

changelog/2582.trivial

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added ``fix-lint`` tox environment to run automatic pep8 fixes on the code.

testing/code/test_excinfo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,10 @@ def xyz():
144144
xyz()
145145
""")
146146
try:
147-
exec (source.compile())
147+
exec(source.compile())
148148
except NameError:
149149
tb = _pytest._code.ExceptionInfo().traceback
150-
print (tb[-1].getsource())
150+
print(tb[-1].getsource())
151151
s = str(tb[-1].getsource())
152152
assert s.startswith("def xyz():\n try:")
153153
assert s.strip().endswith("except somenoname:")
@@ -341,7 +341,7 @@ def test_excinfo_errisinstance():
341341

342342
def test_excinfo_no_sourcecode():
343343
try:
344-
exec ("raise ValueError()")
344+
exec("raise ValueError()")
345345
except ValueError:
346346
excinfo = _pytest._code.ExceptionInfo()
347347
s = str(excinfo.traceback[-1])
@@ -431,7 +431,7 @@ def importasmod(source):
431431
def excinfo_from_exec(self, source):
432432
source = _pytest._code.Source(source).strip()
433433
try:
434-
exec (source.compile())
434+
exec(source.compile())
435435
except KeyboardInterrupt:
436436
raise
437437
except:
@@ -471,7 +471,7 @@ def test_repr_source_not_existing(self):
471471
pr = FormattedExcinfo()
472472
co = compile("raise ValueError()", "", "exec")
473473
try:
474-
exec (co)
474+
exec(co)
475475
except ValueError:
476476
excinfo = _pytest._code.ExceptionInfo()
477477
repr = pr.repr_excinfo(excinfo)
@@ -486,7 +486,7 @@ def test_repr_many_line_source_not_existing(self):
486486
raise ValueError()
487487
""", "", "exec")
488488
try:
489-
exec (co)
489+
exec(co)
490490
except ValueError:
491491
excinfo = _pytest._code.ExceptionInfo()
492492
repr = pr.repr_excinfo(excinfo)
@@ -992,7 +992,7 @@ def i():
992992
tw = TWMock()
993993
r.toterminal(tw)
994994
for line in tw.lines:
995-
print (line)
995+
print(line)
996996
assert tw.lines[0] == ""
997997
assert tw.lines[1] == " def f():"
998998
assert tw.lines[2] == "> g()"
@@ -1040,7 +1040,7 @@ def h():
10401040
tw = TWMock()
10411041
r.toterminal(tw)
10421042
for line in tw.lines:
1043-
print (line)
1043+
print(line)
10441044
assert tw.lines[0] == ""
10451045
assert tw.lines[1] == " def f():"
10461046
assert tw.lines[2] == " try:"

testing/code/test_source.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,12 @@ def f(x):
170170
def test_compile(self):
171171
co = _pytest._code.compile("x=3")
172172
d = {}
173-
exec (co, d)
173+
exec(co, d)
174174
assert d['x'] == 3
175175

176176
def test_compile_and_getsource_simple(self):
177177
co = _pytest._code.compile("x=3")
178-
exec (co)
178+
exec(co)
179179
source = _pytest._code.Source(co)
180180
assert str(source) == "x=3"
181181

@@ -335,21 +335,6 @@ def __init__(self, *args):
335335
assert len(l) == 1
336336

337337

338-
def test_getstartingblock_multiline():
339-
class A(object):
340-
def __init__(self, *args):
341-
frame = sys._getframe(1)
342-
self.source = _pytest._code.Frame(frame).statement
343-
344-
x = A('x',
345-
'y'
346-
,
347-
'z')
348-
349-
l = [i for i in x.source.lines if i.strip()]
350-
assert len(l) == 4
351-
352-
353338
def test_getline_finally():
354339
def c(): pass
355340
excinfo = pytest.raises(TypeError, """
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# flake8: noqa
2+
import sys
3+
4+
import _pytest._code
5+
6+
7+
def test_getstartingblock_multiline():
8+
"""
9+
This test was originally found in test_source.py, but it depends on the weird
10+
formatting of the ``x = A`` construct seen here and our autopep8 tool can only exclude entire
11+
files (it does not support excluding lines/blocks using the traditional #noqa comment yet,
12+
see hhatto/autopep8#307). It was considered better to just move this single test to its own
13+
file and exclude it from autopep8 than try to complicate things.
14+
"""
15+
class A(object):
16+
def __init__(self, *args):
17+
frame = sys._getframe(1)
18+
self.source = _pytest._code.Frame(frame).statement
19+
20+
x = A('x',
21+
'y'
22+
,
23+
'z')
24+
25+
l = [i for i in x.source.lines if i.strip()]
26+
assert len(l) == 4

testing/test_capture.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,14 @@ def test_capturing_basic_api(self, method):
8383
assert outerr == ("", "")
8484
outerr = capman.suspendcapture()
8585
assert outerr == ("", "")
86-
print ("hello")
86+
print("hello")
8787
out, err = capman.suspendcapture()
8888
if method == "no":
8989
assert old == (sys.stdout, sys.stderr, sys.stdin)
9090
else:
9191
assert not out
9292
capman.resumecapture()
93-
print ("hello")
93+
print("hello")
9494
out, err = capman.suspendcapture()
9595
if method != "no":
9696
assert out == "hello\n"
@@ -288,7 +288,7 @@ def test_logging():
288288
stream.close() # to free memory/release resources
289289
""")
290290
result = testdir.runpytest_subprocess(p)
291-
result.stderr.str().find("atexit") == -1
291+
assert result.stderr.str().find("atexit") == -1
292292

293293
def test_logging_and_immediate_setupteardown(self, testdir):
294294
p = testdir.makepyfile("""
@@ -305,7 +305,7 @@ def teardown_function(function):
305305
assert 0
306306
""")
307307
for optargs in (('--capture=sys',), ('--capture=fd',)):
308-
print (optargs)
308+
print(optargs)
309309
result = testdir.runpytest_subprocess(p, *optargs)
310310
s = result.stdout.str()
311311
result.stdout.fnmatch_lines([
@@ -331,7 +331,7 @@ def teardown_module(function):
331331
assert 0
332332
""")
333333
for optargs in (('--capture=sys',), ('--capture=fd',)):
334-
print (optargs)
334+
print(optargs)
335335
result = testdir.runpytest_subprocess(p, *optargs)
336336
s = result.stdout.str()
337337
result.stdout.fnmatch_lines([
@@ -879,7 +879,7 @@ def test_capturing_reset_simple(self):
879879

880880
def test_capturing_readouterr(self):
881881
with self.getcapture() as cap:
882-
print ("hello world")
882+
print("hello world")
883883
sys.stderr.write("hello error\n")
884884
out, err = cap.readouterr()
885885
assert out == "hello world\n"
@@ -890,7 +890,7 @@ def test_capturing_readouterr(self):
890890

891891
def test_capturing_readouterr_unicode(self):
892892
with self.getcapture() as cap:
893-
print ("hx\xc4\x85\xc4\x87")
893+
print("hx\xc4\x85\xc4\x87")
894894
out, err = cap.readouterr()
895895
assert out == py.builtin._totext("hx\xc4\x85\xc4\x87\n", "utf8")
896896

@@ -905,7 +905,7 @@ def test_capturing_readouterr_decode_error_handling(self):
905905

906906
def test_reset_twice_error(self):
907907
with self.getcapture() as cap:
908-
print ("hello")
908+
print("hello")
909909
out, err = cap.readouterr()
910910
pytest.raises(ValueError, cap.stop_capturing)
911911
assert out == "hello\n"
@@ -919,7 +919,7 @@ def test_capturing_modify_sysouterr_in_between(self):
919919
sys.stderr.write("world")
920920
sys.stdout = capture.CaptureIO()
921921
sys.stderr = capture.CaptureIO()
922-
print ("not seen")
922+
print("not seen")
923923
sys.stderr.write("not seen\n")
924924
out, err = cap.readouterr()
925925
assert out == "hello"
@@ -929,9 +929,9 @@ def test_capturing_modify_sysouterr_in_between(self):
929929

930930
def test_capturing_error_recursive(self):
931931
with self.getcapture() as cap1:
932-
print ("cap1")
932+
print("cap1")
933933
with self.getcapture() as cap2:
934-
print ("cap2")
934+
print("cap2")
935935
out2, err2 = cap2.readouterr()
936936
out1, err1 = cap1.readouterr()
937937
assert out1 == "cap1\n"
@@ -961,9 +961,9 @@ def test_stdin_restored(self):
961961
assert sys.stdin is old
962962

963963
def test_stdin_nulled_by_default(self):
964-
print ("XXX this test may well hang instead of crashing")
965-
print ("XXX which indicates an error in the underlying capturing")
966-
print ("XXX mechanisms")
964+
print("XXX this test may well hang instead of crashing")
965+
print("XXX which indicates an error in the underlying capturing")
966+
print("XXX mechanisms")
967967
with self.getcapture():
968968
pytest.raises(IOError, "sys.stdin.read()")
969969

testing/test_conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ def test_no_conftest(fxtr):
321321
# use value from parent dir's
322322
323323
"""))
324-
print ("created directory structure:")
324+
print("created directory structure:")
325325
for x in testdir.tmpdir.visit():
326-
print (" " + x.relto(testdir.tmpdir))
326+
print(" " + x.relto(testdir.tmpdir))
327327

328328
return {
329329
"runner": runner,

testing/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def teardown_function(func):
226226
raise ValueError(42)
227227
""")
228228
reps = rec.getreports("pytest_runtest_logreport")
229-
print (reps)
229+
print(reps)
230230
for i in range(2):
231231
assert reps[i].nodeid.endswith("test_method")
232232
assert reps[i].passed
@@ -253,7 +253,7 @@ def test_method(self):
253253
assert True
254254
""")
255255
reps = rec.getreports("pytest_runtest_logreport")
256-
print (reps)
256+
print(reps)
257257
assert len(reps) == 3
258258
#
259259
assert reps[0].nodeid.endswith("test_method")

tox.ini

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,14 @@ commands =
149149
rm -rf /tmp/doc-exec*
150150
make regen
151151

152+
[testenv:fix-lint]
153+
skipsdist = True
154+
usedevelop = True
155+
deps =
156+
autopep8
157+
commands =
158+
autopep8 --in-place -r --max-line-length=120 --exclude=vendored_packages,test_source_multiline_block.py _pytest testing
159+
152160
[testenv:jython]
153161
changedir = testing
154162
commands =

0 commit comments

Comments
 (0)