diff options
author | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2018-05-17 23:31:16 +0200 |
---|---|---|
committer | Ronny Pfannschmidt <opensource@ronnypfannschmidt.de> | 2018-05-23 16:45:09 +0200 |
commit | 9aacb4635e81edd6ecf281d4f6c0cfc8e94ab301 (patch) | |
tree | 195e1646c52970c23a8c1e0d3460841646a32e69 /_pytest | |
parent | d41119ed04b4b48e0d5db74d7a4ee29192d9e6b1 (diff) | |
download | pytest-9aacb4635e81edd6ecf281d4f6c0cfc8e94ab301.tar.gz |
run pyupgrade
Diffstat (limited to '_pytest')
-rw-r--r-- | _pytest/_code/code.py | 2 | ||||
-rw-r--r-- | _pytest/assertion/rewrite.py | 4 | ||||
-rw-r--r-- | _pytest/assertion/truncate.py | 6 | ||||
-rw-r--r-- | _pytest/assertion/util.py | 8 | ||||
-rw-r--r-- | _pytest/capture.py | 4 | ||||
-rw-r--r-- | _pytest/config.py | 8 | ||||
-rw-r--r-- | _pytest/fixtures.py | 14 | ||||
-rw-r--r-- | _pytest/logging.py | 4 | ||||
-rw-r--r-- | _pytest/main.py | 2 | ||||
-rw-r--r-- | _pytest/mark/legacy.py | 2 | ||||
-rw-r--r-- | _pytest/mark/structures.py | 2 | ||||
-rw-r--r-- | _pytest/outcomes.py | 2 | ||||
-rw-r--r-- | _pytest/pytester.py | 2 | ||||
-rw-r--r-- | _pytest/python.py | 12 | ||||
-rw-r--r-- | _pytest/python_api.py | 18 | ||||
-rw-r--r-- | _pytest/recwarn.py | 10 | ||||
-rw-r--r-- | _pytest/runner.py | 6 | ||||
-rw-r--r-- | _pytest/setuponly.py | 4 | ||||
-rw-r--r-- | _pytest/skipping.py | 4 |
19 files changed, 57 insertions, 57 deletions
diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py index 76e143774..46abb15bb 100644 --- a/_pytest/_code/code.py +++ b/_pytest/_code/code.py @@ -455,7 +455,7 @@ class ExceptionInfo(object): """ __tracebackhide__ = True if not re.search(regexp, str(self.value)): - assert 0, "Pattern '{0!s}' not found in '{1!s}'".format( + assert 0, "Pattern '{!s}' not found in '{!s}'".format( regexp, self.value) return True diff --git a/_pytest/assertion/rewrite.py b/_pytest/assertion/rewrite.py index 0499a792f..ff1261788 100644 --- a/_pytest/assertion/rewrite.py +++ b/_pytest/assertion/rewrite.py @@ -904,7 +904,7 @@ class AssertionRewriter(ast.NodeVisitor): self.push_format_context() left_res, left_expl = self.visit(comp.left) if isinstance(comp.left, (ast.Compare, ast.BoolOp)): - left_expl = "({0})".format(left_expl) + left_expl = "({})".format(left_expl) res_variables = [self.variable() for i in range(len(comp.ops))] load_names = [ast.Name(v, ast.Load()) for v in res_variables] store_names = [ast.Name(v, ast.Store()) for v in res_variables] @@ -915,7 +915,7 @@ class AssertionRewriter(ast.NodeVisitor): for i, op, next_operand in it: next_res, next_expl = self.visit(next_operand) if isinstance(next_operand, (ast.Compare, ast.BoolOp)): - next_expl = "({0})".format(next_expl) + next_expl = "({})".format(next_expl) results.append(next_res) sym = binop_map[op.__class__] syms.append(ast.Str(sym)) diff --git a/_pytest/assertion/truncate.py b/_pytest/assertion/truncate.py index 2ed12e2e5..912a2f16f 100644 --- a/_pytest/assertion/truncate.py +++ b/_pytest/assertion/truncate.py @@ -69,10 +69,10 @@ def _truncate_explanation(input_lines, max_lines=None, max_chars=None): truncated_line_count += 1 # Account for the part-truncated final line msg = '...Full output truncated' if truncated_line_count == 1: - msg += ' ({0} line hidden)'.format(truncated_line_count) + msg += ' ({} line hidden)'.format(truncated_line_count) else: - msg += ' ({0} lines hidden)'.format(truncated_line_count) - msg += ", {0}" .format(USAGE_MSG) + msg += ' ({} lines hidden)'.format(truncated_line_count) + msg += ", {}" .format(USAGE_MSG) truncated_explanation.extend([ six.text_type(""), six.text_type(msg), diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 7848d0997..88d1ebc69 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -275,14 +275,14 @@ def _compare_eq_set(left, right, verbose=False): def _compare_eq_dict(left, right, verbose=False): explanation = [] common = set(left).intersection(set(right)) - same = dict((k, left[k]) for k in common if left[k] == right[k]) + same = {k: left[k] for k in common if left[k] == right[k]} if same and verbose < 2: explanation += [u('Omitting %s identical items, use -vv to show') % len(same)] elif same: explanation += [u('Common items:')] explanation += pprint.pformat(same).splitlines() - diff = set(k for k in common if left[k] != right[k]) + diff = {k for k in common if left[k] != right[k]} if diff: explanation += [u('Differing items:')] for k in diff: @@ -292,12 +292,12 @@ def _compare_eq_dict(left, right, verbose=False): if extra_left: explanation.append(u('Left contains more items:')) explanation.extend(pprint.pformat( - dict((k, left[k]) for k in extra_left)).splitlines()) + {k: left[k] for k in extra_left}).splitlines()) extra_right = set(right) - set(left) if extra_right: explanation.append(u('Right contains more items:')) explanation.extend(pprint.pformat( - dict((k, right[k]) for k in extra_right)).splitlines()) + {k: right[k] for k in extra_right}).splitlines()) return explanation diff --git a/_pytest/capture.py b/_pytest/capture.py index d71f59ac2..99ba817a0 100644 --- a/_pytest/capture.py +++ b/_pytest/capture.py @@ -184,12 +184,12 @@ capture_fixtures = {'capfd', 'capfdbinary', 'capsys', 'capsysbinary'} def _ensure_only_one_capture_fixture(request, name): - fixtures = set(request.fixturenames) & capture_fixtures - set((name,)) + fixtures = set(request.fixturenames) & capture_fixtures - {name} if fixtures: fixtures = sorted(fixtures) fixtures = fixtures[0] if len(fixtures) == 1 else fixtures raise request.raiseerror( - "cannot use {0} and {1} at the same time".format( + "cannot use {} and {} at the same time".format( fixtures, name, ), ) diff --git a/_pytest/config.py b/_pytest/config.py index 86632ed64..426e9627c 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -89,7 +89,7 @@ def filename_arg(path, optname): :optname: name of the option """ if os.path.isdir(path): - raise UsageError("{0} must be a filename, given: {1}".format(optname, path)) + raise UsageError("{} must be a filename, given: {}".format(optname, path)) return path @@ -100,7 +100,7 @@ def directory_arg(path, optname): :optname: name of the option """ if not os.path.isdir(path): - raise UsageError("{0} must be a directory, given: {1}".format(optname, path)) + raise UsageError("{} must be a directory, given: {}".format(optname, path)) return path @@ -253,7 +253,7 @@ class PytestPluginManager(PluginManager): def register(self, plugin, name=None): if name in ['pytest_catchlog', 'pytest_capturelog']: - self._warn('{0} plugin has been merged into the core, ' + self._warn('{} plugin has been merged into the core, ' 'please remove it from your requirements.'.format( name.replace('_', '-'))) return @@ -735,7 +735,7 @@ class Argument(object): args += ['type: ' + repr(self.type)] if hasattr(self, 'default'): args += ['default: ' + repr(self.default)] - return 'Argument({0})'.format(', '.join(args)) + return 'Argument({})'.format(', '.join(args)) class OptionGroup(object): diff --git a/_pytest/fixtures.py b/_pytest/fixtures.py index 7b109ec11..5bbe94db8 100644 --- a/_pytest/fixtures.py +++ b/_pytest/fixtures.py @@ -493,8 +493,8 @@ class FixtureRequest(FuncargnamesCompatAttr): source_path = source_path.relto(funcitem.config.rootdir) msg = ( "The requested fixture has no parameter defined for the " - "current test.\n\nRequested fixture '{0}' defined in:\n{1}" - "\n\nRequested here:\n{2}:{3}".format( + "current test.\n\nRequested fixture '{}' defined in:\n{}" + "\n\nRequested here:\n{}:{}".format( fixturedef.argname, getlocation(fixturedef.func, funcitem.config.rootdir), source_path, @@ -612,8 +612,8 @@ def scope2index(scope, descr, where=None): return scopes.index(scope) except ValueError: raise ValueError( - "{0} {1}has an unsupported scope value '{2}'".format( - descr, 'from {0} '.format(where) if where else '', + "{} {}has an unsupported scope value '{}'".format( + descr, 'from {} '.format(where) if where else '', scope) ) @@ -681,10 +681,10 @@ class FixtureLookupErrorRepr(TerminalRepr): tw.line(tbline.rstrip()) lines = self.errorstring.split("\n") if lines: - tw.line('{0} {1}'.format(FormattedExcinfo.fail_marker, + tw.line('{} {}'.format(FormattedExcinfo.fail_marker, lines[0].strip()), red=True) for line in lines[1:]: - tw.line('{0} {1}'.format(FormattedExcinfo.flow_marker, + tw.line('{} {}'.format(FormattedExcinfo.flow_marker, line.strip()), red=True) tw.line() tw.line("%s:%d" % (self.filename, self.firstlineno + 1)) @@ -732,7 +732,7 @@ class FixtureDef(object): self.scope = scope self.scopenum = scope2index( scope or "function", - descr='fixture {0}'.format(func.__name__), + descr='fixture {}'.format(func.__name__), where=baseid ) self.params = params diff --git a/_pytest/logging.py b/_pytest/logging.py index 66ed6900b..fc511f767 100644 --- a/_pytest/logging.py +++ b/_pytest/logging.py @@ -318,8 +318,8 @@ def get_actual_log_level(config, *setting_names): except ValueError: # Python logging does not recognise this as a logging level raise pytest.UsageError( - "'{0}' is not recognized as a logging level name for " - "'{1}'. Please consider passing the " + "'{}' is not recognized as a logging level name for " + "'{}'. Please consider passing the " "logging level num instead.".format( log_level, setting_name)) diff --git a/_pytest/main.py b/_pytest/main.py index 6c4bd65bb..b3027fc25 100644 --- a/_pytest/main.py +++ b/_pytest/main.py @@ -112,7 +112,7 @@ def wrap_session(config, doit): except KeyboardInterrupt: excinfo = _pytest._code.ExceptionInfo() if initstate < 2 and isinstance(excinfo.value, exit.Exception): - sys.stderr.write('{0}: {1}\n'.format( + sys.stderr.write('{}: {}\n'.format( excinfo.typename, excinfo.value.msg)) config.hook.pytest_keyboard_interrupt(excinfo=excinfo) session.exitstatus = EXIT_INTERRUPTED diff --git a/_pytest/mark/legacy.py b/_pytest/mark/legacy.py index 5c7b8d001..30c7239bf 100644 --- a/_pytest/mark/legacy.py +++ b/_pytest/mark/legacy.py @@ -17,7 +17,7 @@ class MarkMapping(object): @classmethod def from_item(cls, item): - mark_names = set(mark.name for mark in item.iter_markers()) + mark_names = {mark.name for mark in item.iter_markers()} return cls(mark_names) def __getitem__(self, name): diff --git a/_pytest/mark/structures.py b/_pytest/mark/structures.py index 72fd264b2..8ec6bbce9 100644 --- a/_pytest/mark/structures.py +++ b/_pytest/mark/structures.py @@ -296,7 +296,7 @@ class MarkInfo(object): return cls([mark]) def __repr__(self): - return "<MarkInfo {0!r}>".format(self.combined) + return "<MarkInfo {!r}>".format(self.combined) def add_mark(self, mark): """ add a MarkInfo with the given args and kwargs. """ diff --git a/_pytest/outcomes.py b/_pytest/outcomes.py index 640c5773a..7ced846ea 100644 --- a/_pytest/outcomes.py +++ b/_pytest/outcomes.py @@ -75,7 +75,7 @@ def skip(msg="", **kwargs): allow_module_level = kwargs.pop('allow_module_level', False) if kwargs: keys = [k for k in kwargs.keys()] - raise TypeError('unexpected keyword arguments: {0}'.format(keys)) + raise TypeError('unexpected keyword arguments: {}'.format(keys)) raise Skipped(msg=msg, allow_module_level=allow_module_level) diff --git a/_pytest/pytester.py b/_pytest/pytester.py index 27dd8289d..f2e972075 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -97,7 +97,7 @@ class LsofFdLeakChecker(object): gc.collect() lines2 = self.get_open_files() - new_fds = set([t[0] for t in lines2]) - set([t[0] for t in lines1]) + new_fds = {t[0] for t in lines2} - {t[0] for t in lines1} leaked_files = [t for t in lines2 if t[0] in new_fds] if leaked_files: error = [] diff --git a/_pytest/python.py b/_pytest/python.py index 8bcb051a2..1e8e0cd1b 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -813,7 +813,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): if scope is None: scope = _find_parametrized_scope(argnames, self._arg2fixturedefs, indirect) - scopenum = scope2index(scope, descr='call to {0}'.format(self.parametrize)) + scopenum = scope2index(scope, descr='call to {}'.format(self.parametrize)) valtypes = {} for arg in argnames: if arg not in self.fixturenames: @@ -858,8 +858,8 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): for a_id, param, param_index in elements: if len(param.values) != len(argnames): raise ValueError( - 'In "parametrize" the number of values ({0}) must be ' - 'equal to the number of names ({1})'.format( + 'In "parametrize" the number of values ({}) must be ' + 'equal to the number of names ({})'.format( param.values, argnames)) newcallspec = callspec.copy(self) newcallspec.setmulti2(valtypes, argnames, param.values, a_id, @@ -1016,7 +1016,7 @@ def _show_fixtures_per_test(config, session): return if verbose > 0: bestrel = get_best_relpath(fixture_def.func) - funcargspec = "{0} -- {1}".format(argname, bestrel) + funcargspec = "{} -- {}".format(argname, bestrel) else: funcargspec = argname tw.line(funcargspec, green=True) @@ -1036,8 +1036,8 @@ def _show_fixtures_per_test(config, session): # this test item does not use any fixtures return tw.line() - tw.sep('-', 'fixtures used by {0}'.format(item.name)) - tw.sep('-', '({0})'.format(get_best_relpath(item.function))) + tw.sep('-', 'fixtures used by {}'.format(item.name)) + tw.sep('-', '({})'.format(get_best_relpath(item.function))) # dict key not used in loop but needed for sorting for _, fixturedefs in sorted(info.name2fixturedefs.items()): assert fixturedefs is not None diff --git a/_pytest/python_api.py b/_pytest/python_api.py index 838a4a50c..de3c9a1fe 100644 --- a/_pytest/python_api.py +++ b/_pytest/python_api.py @@ -79,7 +79,7 @@ class ApproxNumpy(ApproxBase): # shape of the array... import numpy as np - return "approx({0!r})".format(list( + return "approx({!r})".format(list( self._approx_scalar(x) for x in np.asarray(self.expected))) if sys.version_info[0] == 2: @@ -94,7 +94,7 @@ class ApproxNumpy(ApproxBase): try: actual = np.asarray(actual) except: # noqa - raise TypeError("cannot compare '{0}' to numpy.ndarray".format(actual)) + raise TypeError("cannot compare '{}' to numpy.ndarray".format(actual)) if not np.isscalar(actual) and actual.shape != self.expected.shape: return False @@ -123,9 +123,9 @@ class ApproxMapping(ApproxBase): """ def __repr__(self): - return "approx({0!r})".format(dict( - (k, self._approx_scalar(v)) - for k, v in self.expected.items())) + return "approx({!r})".format({ + k: self._approx_scalar(v) + for k, v in self.expected.items()}) def __eq__(self, actual): if set(actual.keys()) != set(self.expected.keys()): @@ -147,7 +147,7 @@ class ApproxSequence(ApproxBase): seq_type = type(self.expected) if seq_type not in (tuple, list, set): seq_type = list - return "approx({0!r})".format(seq_type( + return "approx({!r})".format(seq_type( self._approx_scalar(x) for x in self.expected)) def __eq__(self, actual): @@ -189,9 +189,9 @@ class ApproxScalar(ApproxBase): vetted_tolerance = '???' if sys.version_info[0] == 2: - return '{0} +- {1}'.format(self.expected, vetted_tolerance) + return '{} +- {}'.format(self.expected, vetted_tolerance) else: - return u'{0} \u00b1 {1}'.format(self.expected, vetted_tolerance) + return u'{} \u00b1 {}'.format(self.expected, vetted_tolerance) def __eq__(self, actual): """ @@ -591,7 +591,7 @@ def raises(expected_exception, *args, **kwargs): " derived from BaseException, not %s") raise TypeError(msg % type(exc)) - message = "DID NOT RAISE {0}".format(expected_exception) + message = "DID NOT RAISE {}".format(expected_exception) match_expr = None if not args: diff --git a/_pytest/recwarn.py b/_pytest/recwarn.py index ab0f79c75..7f9fcb30a 100644 --- a/_pytest/recwarn.py +++ b/_pytest/recwarn.py @@ -217,8 +217,8 @@ class WarningsChecker(WarningsRecorder): if not any(issubclass(r.category, self.expected_warning) for r in self): __tracebackhide__ = True - fail("DID NOT WARN. No warnings of type {0} was emitted. " - "The list of emitted warnings is: {1}.".format( + fail("DID NOT WARN. No warnings of type {} was emitted. " + "The list of emitted warnings is: {}.".format( self.expected_warning, [each.message for each in self])) elif self.match_expr is not None: @@ -227,7 +227,7 @@ class WarningsChecker(WarningsRecorder): if re.compile(self.match_expr).search(str(r.message)): break else: - fail("DID NOT WARN. No warnings of type {0} matching" - " ('{1}') was emitted. The list of emitted warnings" - " is: {2}.".format(self.expected_warning, self.match_expr, + fail("DID NOT WARN. No warnings of type {} matching" + " ('{}') was emitted. The list of emitted warnings" + " is: {}.".format(self.expected_warning, self.match_expr, [each.message for each in self])) diff --git a/_pytest/runner.py b/_pytest/runner.py index 6df558a7f..3951f29d5 100644 --- a/_pytest/runner.py +++ b/_pytest/runner.py @@ -95,7 +95,7 @@ def show_test_item(item): tw.write(item._nodeid) used_fixtures = sorted(item._fixtureinfo.name2fixturedefs.keys()) if used_fixtures: - tw.write(' (fixtures used: {0})'.format(', '.join(used_fixtures))) + tw.write(' (fixtures used: {})'.format(', '.join(used_fixtures))) def pytest_runtest_setup(item): @@ -133,7 +133,7 @@ def _update_current_test_var(item, when): """ var_name = 'PYTEST_CURRENT_TEST' if when: - value = '{0} ({1})'.format(item.nodeid, when) + value = '{} ({})'.format(item.nodeid, when) # don't allow null bytes on environment variables (see #2644, #2957) value = value.replace('\x00', '(null)') os.environ[var_name] = value @@ -297,7 +297,7 @@ class BaseReport(object): def pytest_runtest_makereport(item, call): when = call.when duration = call.stop - call.start - keywords = dict([(x, 1) for x in item.keywords]) + keywords = {x: 1 for x in item.keywords} excinfo = call.excinfo sections = [] if not call.excinfo: diff --git a/_pytest/setuponly.py b/_pytest/setuponly.py index a1c7457d7..1af8fffb5 100644 --- a/_pytest/setuponly.py +++ b/_pytest/setuponly.py @@ -57,10 +57,10 @@ def _show_fixture_action(fixturedef, msg): if msg == 'SETUP': deps = sorted(arg for arg in fixturedef.argnames if arg != 'request') if deps: - tw.write(' (fixtures used: {0})'.format(', '.join(deps))) + tw.write(' (fixtures used: {})'.format(', '.join(deps))) if hasattr(fixturedef, 'cached_param'): - tw.write('[{0}]'.format(fixturedef.cached_param)) + tw.write('[{}]'.format(fixturedef.cached_param)) if capman: capman.resume_global_capture() diff --git a/_pytest/skipping.py b/_pytest/skipping.py index 36eb4a337..4c5a35364 100644 --- a/_pytest/skipping.py +++ b/_pytest/skipping.py @@ -116,7 +116,7 @@ def pytest_runtest_makereport(item, call): if hasattr(item, '_unexpectedsuccess') and rep.when == "call": from _pytest.compat import _is_unittest_unexpected_success_a_failure if item._unexpectedsuccess: - rep.longrepr = "Unexpected success: {0}".format(item._unexpectedsuccess) + rep.longrepr = "Unexpected success: {}".format(item._unexpectedsuccess) else: rep.longrepr = "Unexpected success" if _is_unittest_unexpected_success_a_failure(): @@ -143,7 +143,7 @@ def pytest_runtest_makereport(item, call): explanation = evalxfail.getexplanation() if is_strict_xfail: rep.outcome = "failed" - rep.longrepr = "[XPASS(strict)] {0}".format(explanation) + rep.longrepr = "[XPASS(strict)] {}".format(explanation) else: rep.outcome = "passed" rep.wasxfail = explanation |