diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py index 797e1d293..2f5e56079 100644 --- a/_pytest/_code/code.py +++ b/_pytest/_code/code.py @@ -168,7 +168,7 @@ class TracebackEntry(object): return self.lineno - self.frame.code.firstlineno def __repr__(self): - return "" % (self.frame.code.path, self.lineno+1) + return "" % (self.frame.code.path, self.lineno + 1) @property def statement(self): @@ -249,7 +249,7 @@ class TracebackEntry(object): raise except: line = "???" - return " File %r:%d in %s\n %s\n" % (fn, self.lineno+1, name, line) + return " File %r:%d in %s\n %s\n" % (fn, self.lineno + 1, name, line) def name(self): return self.frame.code.raw.co_name @@ -315,7 +315,7 @@ class Traceback(list): """ return last non-hidden traceback entry that lead to the exception of a traceback. """ - for i in range(-1, -len(self)-1, -1): + for i in range(-1, -len(self) - 1, -1): entry = self[i] if not entry.ishidden(): return entry @@ -405,7 +405,7 @@ class ExceptionInfo(object): exconly = self.exconly(tryshort=True) entry = self.traceback.getcrashentry() path, lineno = entry.frame.code.raw.co_filename, entry.lineno - return ReprFileLocation(path, lineno+1, exconly) + return ReprFileLocation(path, lineno + 1, exconly) def getrepr(self, showlocals=False, style="long", abspath=False, tbfilter=True, funcargs=False): @@ -469,7 +469,7 @@ class FormattedExcinfo(object): def _getindent(self, source): # figure out indent for given source try: - s = str(source.getstatement(len(source)-1)) + s = str(source.getstatement(len(source) - 1)) except KeyboardInterrupt: raise except: @@ -513,7 +513,7 @@ class FormattedExcinfo(object): for line in source.lines[:line_index]: lines.append(space_prefix + line) lines.append(self.flow_marker + " " + source.lines[line_index]) - for line in source.lines[line_index+1:]: + for line in source.lines[line_index + 1:]: lines.append(space_prefix + line) if excinfo is not None: indent = 4 if short else self._getindent(source) @@ -579,7 +579,7 @@ class FormattedExcinfo(object): else: message = excinfo and excinfo.typename or "" path = self._makepath(entry.path) - filelocrepr = ReprFileLocation(path, entry.lineno+1, message) + filelocrepr = ReprFileLocation(path, entry.lineno + 1, message) localsrepr = None if not short: localsrepr = self.repr_locals(entry.locals) @@ -758,7 +758,7 @@ class ReprTraceback(TerminalRepr): tw.line("") entry.toterminal(tw) if i < len(self.reprentries) - 1: - next_entry = self.reprentries[i+1] + next_entry = self.reprentries[i + 1] if entry.style == "long" or \ entry.style == "short" and next_entry.style == "long": tw.sep(self.entrysep) diff --git a/_pytest/_code/source.py b/_pytest/_code/source.py index 54aaca2e9..8b5268533 100644 --- a/_pytest/_code/source.py +++ b/_pytest/_code/source.py @@ -73,7 +73,7 @@ class Source(object): start, end = 0, len(self) while start < end and not self.lines[start].strip(): start += 1 - while end > start and not self.lines[end-1].strip(): + while end > start and not self.lines[end - 1].strip(): end -= 1 source = Source() source.lines[:] = self.lines[start:end] @@ -95,7 +95,7 @@ class Source(object): all lines indented by the given indent-string. """ newsource = Source() - newsource.lines = [(indent+line) for line in self.lines] + newsource.lines = [(indent + line) for line in self.lines] return newsource def getstatement(self, lineno, assertion=False): @@ -144,7 +144,7 @@ class Source(object): source = str(self) try: #compile(source+'\n', "x", "exec") - syntax_checker(source+'\n') + syntax_checker(source + '\n') except KeyboardInterrupt: raise except Exception: @@ -180,7 +180,7 @@ class Source(object): # re-represent syntax errors from parsing python strings msglines = self.lines[:ex.lineno] if ex.offset: - msglines.append(" "*ex.offset + '^') + msglines.append(" " * ex.offset + '^') msglines.append("(code was compiled probably from here: %s)" % filename) newex = SyntaxError('\n'.join(msglines)) newex.offset = ex.offset @@ -274,7 +274,7 @@ def deindent(lines, offset=None): line = line.expandtabs() s = line.lstrip() if s: - offset = len(line)-len(s) + offset = len(line) - len(s) break else: offset = 0 @@ -393,7 +393,7 @@ def getstatementrange_old(lineno, source, assertion=False): raise IndexError("likely a subclass") if "assert" not in line and "raise" not in line: continue - trylines = source.lines[start:lineno+1] + trylines = source.lines[start:lineno + 1] # quick hack to prepare parsing an indented line with # compile_command() (which errors on "return" outside defs) trylines.insert(0, 'def xxx():') @@ -405,7 +405,7 @@ def getstatementrange_old(lineno, source, assertion=False): continue # 2. find the end of the statement - for end in range(lineno+1, len(source)+1): + for end in range(lineno + 1, len(source) + 1): trysource = source[start:end] if trysource.isparseable(): return start, end diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 06eda8d91..c2a5ddee0 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -82,7 +82,7 @@ def _format_lines(lines): stack.append(len(result)) stackcnt[-1] += 1 stackcnt.append(0) - result.append(u(' +') + u(' ')*(len(stack)-1) + s + line[1:]) + result.append(u(' +') + u(' ') * (len(stack) - 1) + s + line[1:]) elif line.startswith('}'): stack.pop() stackcnt.pop() @@ -91,7 +91,7 @@ def _format_lines(lines): assert line[0] in ['~', '>'] stack[-1] += 1 indent = len(stack) if line.startswith('~') else len(stack) - 1 - result.append(u(' ')*indent + line[1:]) + result.append(u(' ') * indent + line[1:]) assert len(stack) == 1 return result @@ -106,8 +106,8 @@ except NameError: def assertrepr_compare(config, op, left, right): """Return specialised explanations for some operators/operands""" width = 80 - 15 - len(op) - 2 # 15 chars indentation, 1 space around op - left_repr = py.io.saferepr(left, maxsize=int(width//2)) - right_repr = py.io.saferepr(right, maxsize=width-len(left_repr)) + left_repr = py.io.saferepr(left, maxsize=int(width // 2)) + right_repr = py.io.saferepr(right, maxsize=width - len(left_repr)) summary = u('%s %s %s') % (ecu(left_repr), op, ecu(right_repr)) @@ -285,7 +285,7 @@ def _compare_eq_dict(left, right, verbose=False): def _notin_text(term, text, verbose=False): index = text.find(term) head = text[:index] - tail = text[index+len(term):] + tail = text[index + len(term):] correct_text = head + tail diff = _diff_text(correct_text, text, verbose) newdiff = [u('%s is contained here:') % py.io.saferepr(term, maxsize=42)] diff --git a/_pytest/compat.py b/_pytest/compat.py index 22cba8450..d89c2922f 100644 --- a/_pytest/compat.py +++ b/_pytest/compat.py @@ -68,7 +68,7 @@ def getlocation(function, curdir): lineno = py.builtin._getcode(function).co_firstlineno if fn.relto(curdir): fn = fn.relto(curdir) - return "%s:%d" % (fn, lineno+1) + return "%s:%d" % (fn, lineno + 1) def num_mock_patch_args(function): diff --git a/_pytest/config.py b/_pytest/config.py index a96e6a015..9e6a92e18 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -511,7 +511,7 @@ class Parser: for i, grp in enumerate(self._groups): if grp.name == after: break - self._groups.insert(i+1, group) + self._groups.insert(i + 1, group) return group def addoption(self, *opts, **attrs): diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index aee55c8fa..f489a87e2 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -174,7 +174,7 @@ def reorder_items_atscope(items, ignore, argkeys_cache, scopenum): items_before, items_same, items_other, newignore = \ slice_items(items, ignore, argkeys_cache[scopenum]) items_before = reorder_items_atscope( - items_before, ignore, argkeys_cache,scopenum+1) + items_before, ignore, argkeys_cache,scopenum + 1) if items_same is None: # nothing to reorder in this scope assert items_other is None @@ -631,9 +631,9 @@ class FixtureLookupError(LookupError): lines, _ = inspect.getsourcelines(get_real_func(function)) except (IOError, IndexError, TypeError): error_msg = "file %s, line %s: source code not available" - addline(error_msg % (fspath, lineno+1)) + addline(error_msg % (fspath, lineno + 1)) else: - addline("file %s, line %s" % (fspath, lineno+1)) + addline("file %s, line %s" % (fspath, lineno + 1)) for i, line in enumerate(lines): line = line.rstrip() addline(" " + line) @@ -675,12 +675,12 @@ class FixtureLookupErrorRepr(TerminalRepr): tw.line('{0} {1}'.format(FormattedExcinfo.flow_marker, line.strip()), red=True) tw.line() - tw.line("%s:%d" % (self.filename, self.firstlineno+1)) + tw.line("%s:%d" % (self.filename, self.firstlineno + 1)) def fail_fixturefunc(fixturefunc, msg): fs, lineno = getfslineno(fixturefunc) - location = "%s:%s" % (fs, lineno+1) + location = "%s:%s" % (fs, lineno + 1) source = _pytest._code.Source(fixturefunc) fail(msg + ":\n\n" + str(source.indent()) + "\n" + location, pytrace=False) @@ -989,7 +989,7 @@ class FixtureManager: if nodeid.startswith(baseid): if baseid: i = len(baseid) - nextchar = nodeid[i:i+1] + nextchar = nodeid[i:i + 1] if nextchar and nextchar not in ":/": continue autousenames.extend(basenames) diff --git a/_pytest/main.py b/_pytest/main.py index 3e9c10b59..74acc409d 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -160,7 +160,7 @@ def pytest_runtestloop(session): return True for i, item in enumerate(session.items): - nextitem = session.items[i+1] if i+1 < len(session.items) else None + nextitem = session.items[i + 1] if i + 1 < len(session.items) else None item.config.hook.pytest_runtest_protocol(item=item, nextitem=nextitem) if session.shouldstop: raise session.Interrupted(session.shouldstop) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 223bdd79b..bbe95f504 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -763,7 +763,7 @@ class Testdir: res = RunResult(reprec.ret, out.split("\n"), err.split("\n"), - time.time()-now) + time.time() - now) res.reprec = reprec return res @@ -948,7 +948,7 @@ class Testdir: f2.close() self._dump_lines(out, sys.stdout) self._dump_lines(err, sys.stderr) - return RunResult(ret, out, err, time.time()-now) + return RunResult(ret, out, err, time.time() - now) def _dump_lines(self, lines, fp): try: @@ -1105,7 +1105,7 @@ class LineMatcher: """ for i, line in enumerate(self.lines): if fnline == line or fnmatch(line, fnline): - return self.lines[i+1:] + return self.lines[i + 1:] raise ValueError("line %r not found in output" % fnline) def _log(self, *args): diff --git a/_pytest/python.py b/_pytest/python.py index cb42c3fe2..b12cc926f 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -947,7 +947,7 @@ def _idval(val, argname, idx, idfn, config=None): return str(val) elif isclass(val) and hasattr(val, '__name__'): return val.__name__ - return str(argname)+str(idx) + return str(argname) + str(idx) def _idvalset(idx, parameterset, argnames, idfn, ids, config=None): diff --git a/_pytest/runner.py b/_pytest/runner.py index d029394ca..0ef3b30fb 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -245,7 +245,7 @@ class BaseReport(object): def pytest_runtest_makereport(item, call): when = call.when - duration = call.stop-call.start + duration = call.stop - call.start keywords = dict([(x,1) for x in item.keywords]) excinfo = call.excinfo sections = [] diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 1b1609600..b95e0cc4c 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -255,7 +255,7 @@ class TestGeneralUsage(object): if path.basename.startswith("conftest"): return MyCollector(path, parent) """) - result = testdir.runpytest(c.basename+"::"+"xyz") + result = testdir.runpytest(c.basename + "::" + "xyz") assert result.ret == 0 result.stdout.fnmatch_lines([ "*1 pass*", diff --git a/testing/code/test_excinfo.py b/testing/code/test_excinfo.py index 73fd51595..96e42de16 100644 --- a/testing/code/test_excinfo.py +++ b/testing/code/test_excinfo.py @@ -143,7 +143,7 @@ class TestTraceback_f_g_h(object): traceback = self.excinfo.traceback newtraceback = traceback.cut(path=path, firstlineno=firstlineno) assert len(newtraceback) == 1 - newtraceback = traceback.cut(path=path, lineno=firstlineno+2) + newtraceback = traceback.cut(path=path, lineno=firstlineno + 2) assert len(newtraceback) == 1 def test_traceback_cut_excludepath(self, testdir): @@ -210,7 +210,7 @@ class TestTraceback_f_g_h(object): def f(n): if n == 0: raise RuntimeError("hello") - f(n-1) + f(n - 1) excinfo = pytest.raises(RuntimeError, f, 100) monkeypatch.delattr(excinfo.traceback.__class__, "recursionindex") @@ -492,7 +492,7 @@ raise ValueError() class FakeTracebackEntry(_pytest._code.Traceback.Entry): def __init__(self, tb, excinfo=None): - self.lineno = 5+3 + self.lineno = 5 + 3 @property def frame(self): @@ -582,12 +582,12 @@ raise ValueError() def func1(m, x, y, z): raise ValueError("hello\\nworld") """) - excinfo = pytest.raises(ValueError, mod.func1, "m"*90, 5, 13, "z"*120) + excinfo = pytest.raises(ValueError, mod.func1, "m" * 90, 5, 13, "z" * 120) excinfo.traceback = excinfo.traceback.filter() entry = excinfo.traceback[-1] p = FormattedExcinfo(funcargs=True) reprfuncargs = p.repr_args(entry) - assert reprfuncargs.args[0] == ('m', repr("m"*90)) + assert reprfuncargs.args[0] == ('m', repr("m" * 90)) assert reprfuncargs.args[1] == ('x', '5') assert reprfuncargs.args[2] == ('y', '13') assert reprfuncargs.args[3] == ('z', repr("z" * 120)) diff --git a/testing/code/test_source.py b/testing/code/test_source.py index dc48b29c3..53703fc57 100644 --- a/testing/code/test_source.py +++ b/testing/code/test_source.py @@ -291,9 +291,9 @@ class TestSourceParsingAndCompiling(object): def check(comp, name): co = comp(self.source, name) if not name: - expected = "codegen %s:%d>" % (mypath, mylineno+2+2) + expected = "codegen %s:%d>" % (mypath, mylineno + 2 + 2) else: - expected = "codegen %r %s:%d>" % (name, mypath, mylineno+2+2) + expected = "codegen %r %s:%d>" % (name, mypath, mylineno + 2 + 2) fn = co.co_filename assert fn.endswith(expected) diff --git a/testing/test_assertion.py b/testing/test_assertion.py index e17e74183..45152c00c 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -303,15 +303,15 @@ class TestAssert_reprcompare(object): assert '+ eggs' in diff def test_text_skipping(self): - lines = callequal('a'*50 + 'spam', 'a'*50 + 'eggs') + lines = callequal('a' * 50 + 'spam', 'a' * 50 + 'eggs') assert 'Skipping' in lines[1] for line in lines: - assert 'a'*50 not in line + assert 'a' * 50 not in line def test_text_skipping_verbose(self): - lines = callequal('a'*50 + 'spam', 'a'*50 + 'eggs', verbose=True) - assert '- ' + 'a'*50 + 'spam' in lines - assert '+ ' + 'a'*50 + 'eggs' in lines + lines = callequal('a' * 50 + 'spam', 'a' * 50 + 'eggs', verbose=True) + assert '- ' + 'a' * 50 + 'spam' in lines + assert '+ ' + 'a' * 50 + 'eggs' in lines def test_multiline_text_diff(self): left = 'foo\nspam\nbar' @@ -609,7 +609,7 @@ class TestTruncateExplanation(object): def test_doesnt_truncate_at_when_input_is_5_lines_and_LT_max_chars(self): expl = ['a' * 100 for x in range(5)] - result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8*80) + result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80) assert result == expl def test_truncates_at_8_lines_when_given_list_of_empty_strings(self): @@ -624,7 +624,7 @@ class TestTruncateExplanation(object): def test_truncates_at_8_lines_when_first_8_lines_are_LT_max_chars(self): expl = ['a' for x in range(100)] - result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8*80) + result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80) assert result != expl assert len(result) == 8 + self.LINES_IN_TRUNCATION_MSG assert "Full output truncated" in result[-1] @@ -634,7 +634,7 @@ class TestTruncateExplanation(object): def test_truncates_at_8_lines_when_first_8_lines_are_EQ_max_chars(self): expl = ['a' * 80 for x in range(16)] - result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8*80) + result = truncate._truncate_explanation(expl, max_lines=8, max_chars=8 * 80) assert result != expl assert len(result) == 8 + self.LINES_IN_TRUNCATION_MSG assert "Full output truncated" in result[-1] diff --git a/testing/test_resultlog.py b/testing/test_resultlog.py index 31df4dd39..a8f83d567 100644 --- a/testing/test_resultlog.py +++ b/testing/test_resultlog.py @@ -68,7 +68,7 @@ def test_write_log_entry(): entry_lines = entry.splitlines() assert len(entry_lines) == 5 assert entry_lines[0] == 'F name' - assert entry_lines[1:] == [' '+line for line in longrepr.splitlines()] + assert entry_lines[1:] == [' ' + line for line in longrepr.splitlines()] class TestWithFunctionIntegration(object): diff --git a/testing/test_runner.py b/testing/test_runner.py index 1b796917a..020cc2816 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -395,7 +395,7 @@ def test_callinfo(): assert ci.when == "123" assert ci.result == 0 assert "result" in repr(ci) - ci = runner.CallInfo(lambda: 0/0, '123') + ci = runner.CallInfo(lambda: 0 / 0, '123') assert ci.when == "123" assert not hasattr(ci, 'result') assert ci.excinfo diff --git a/testing/test_runner_xunit.py b/testing/test_runner_xunit.py index 92ba97202..676d119ff 100644 --- a/testing/test_runner_xunit.py +++ b/testing/test_runner_xunit.py @@ -90,7 +90,7 @@ def test_class_setup(testdir): assert not TestSimpleClassSetup.clslevel assert not TestInheritedClassSetupStillWorks.clslevel """) - reprec.assertoutcome(passed=1+2+1) + reprec.assertoutcome(passed=1 + 2 + 1) def test_class_setup_failure_no_teardown(testdir): reprec = testdir.inline_runsource(""" diff --git a/testing/test_skipping.py b/testing/test_skipping.py index afd5df16f..606560f4c 100644 --- a/testing/test_skipping.py +++ b/testing/test_skipping.py @@ -80,7 +80,7 @@ class TestEvaluator(object): %s def test_func(): pass - """ % (lines[i], lines[(i+1) % 2])) + """ % (lines[i], lines[(i + 1) % 2])) ev = MarkEvaluator(item, 'skipif') assert ev assert ev.istrue() diff --git a/tox.ini b/tox.ini index fd0cc814d..521f19153 100644 --- a/tox.ini +++ b/tox.ini @@ -196,6 +196,6 @@ filterwarnings = ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning [flake8] -ignore = E226,E231,E241,E251,E261,E262,E265,E271,E272,E293,E301,E302,E303,E401,E402,E501,E701,E702,E704,E712,E731 +ignore = E231,E241,E251,E261,E262,E265,E271,E272,E293,E301,E302,E303,E401,E402,E501,E701,E702,E704,E712,E731 max-line-length = 120 exclude = _pytest/vendored_packages/pluggy.py