diff options
author | shadchin <shadchin@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:44:30 +0300 |
commit | 2598ef1d0aee359b4b6d5fdd1758916d5907d04f (patch) | |
tree | 012bb94d777798f1f56ac1cec429509766d05181 /contrib/python/pytest/py2/_pytest/python.py | |
parent | 6751af0b0c1b952fede40b19b71da8025b5d8bcf (diff) | |
download | ydb-2598ef1d0aee359b4b6d5fdd1758916d5907d04f.tar.gz |
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/python/pytest/py2/_pytest/python.py')
-rw-r--r-- | contrib/python/pytest/py2/_pytest/python.py | 538 |
1 files changed, 269 insertions, 269 deletions
diff --git a/contrib/python/pytest/py2/_pytest/python.py b/contrib/python/pytest/py2/_pytest/python.py index f7c368b0c4..244c22e191 100644 --- a/contrib/python/pytest/py2/_pytest/python.py +++ b/contrib/python/pytest/py2/_pytest/python.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- """ Python test discovery, setup and run of test functions. """ from __future__ import absolute_import from __future__ import division @@ -10,7 +10,7 @@ import inspect import os import sys import warnings -from functools import partial +from functools import partial from textwrap import dedent import py @@ -39,14 +39,14 @@ from _pytest.compat import safe_str from _pytest.compat import STRING_TYPES from _pytest.config import hookimpl from _pytest.main import FSHookProxy -from _pytest.mark import MARK_GEN +from _pytest.mark import MARK_GEN from _pytest.mark.structures import get_unpacked_marks from _pytest.mark.structures import normalize_mark_list from _pytest.outcomes import fail -from _pytest.outcomes import skip +from _pytest.outcomes import skip from _pytest.pathlib import parts -from _pytest.warning_types import PytestCollectionWarning -from _pytest.warning_types import PytestUnhandledCoroutineWarning +from _pytest.warning_types import PytestCollectionWarning +from _pytest.warning_types import PytestUnhandledCoroutineWarning def pyobj_property(name): @@ -82,7 +82,7 @@ def pytest_addoption(parser): parser.addini( "python_files", type="args", - # NOTE: default is also used in AssertionRewritingHook. + # NOTE: default is also used in AssertionRewritingHook. default=["test_*.py", "*_test.py"], help="glob-style file patterns for Python test module discovery", ) @@ -98,13 +98,13 @@ def pytest_addoption(parser): default=["test"], help="prefixes or glob names for Python test function and method discovery", ) - parser.addini( - "disable_test_id_escaping_and_forfeit_all_rights_to_community_support", - type="bool", - default=False, - help="disable string escape non-ascii characters, might cause unwanted " - "side effects(use at your own risk)", - ) + parser.addini( + "disable_test_id_escaping_and_forfeit_all_rights_to_community_support", + type="bool", + default=False, + help="disable string escape non-ascii characters, might cause unwanted " + "side effects(use at your own risk)", + ) group.addoption( "--import-mode", @@ -129,10 +129,10 @@ def pytest_generate_tests(metafunc): # those alternative spellings are common - raise a specific error to alert # the user alt_spellings = ["parameterize", "parametrise", "parameterise"] - for mark_name in alt_spellings: - if metafunc.definition.get_closest_marker(mark_name): + for mark_name in alt_spellings: + if metafunc.definition.get_closest_marker(mark_name): msg = "{0} has '{1}' mark, spelling should be 'parametrize'" - fail(msg.format(metafunc.function.__name__, mark_name), pytrace=False) + fail(msg.format(metafunc.function.__name__, mark_name), pytrace=False) for marker in metafunc.definition.iter_markers(name="parametrize"): metafunc.parametrize(*marker.args, **marker.kwargs) @@ -160,18 +160,18 @@ def pytest_configure(config): @hookimpl(trylast=True) def pytest_pyfunc_call(pyfuncitem): testfunction = pyfuncitem.obj - iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None) - if iscoroutinefunction is not None and iscoroutinefunction(testfunction): - msg = "Coroutine functions are not natively supported and have been skipped.\n" - msg += "You need to install a suitable plugin for your async framework, for example:\n" - msg += " - pytest-asyncio\n" - msg += " - pytest-trio\n" - msg += " - pytest-tornasync" - warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid))) - skip(msg="coroutine function and no async plugin installed (see warnings)") - funcargs = pyfuncitem.funcargs - testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} - testfunction(**testargs) + iscoroutinefunction = getattr(inspect, "iscoroutinefunction", None) + if iscoroutinefunction is not None and iscoroutinefunction(testfunction): + msg = "Coroutine functions are not natively supported and have been skipped.\n" + msg += "You need to install a suitable plugin for your async framework, for example:\n" + msg += " - pytest-asyncio\n" + msg += " - pytest-trio\n" + msg += " - pytest-tornasync" + warnings.warn(PytestUnhandledCoroutineWarning(msg.format(pyfuncitem.nodeid))) + skip(msg="coroutine function and no async plugin installed (see warnings)") + funcargs = pyfuncitem.funcargs + testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames} + testfunction(**testargs) return True @@ -217,7 +217,7 @@ def pytest_pycollect_makeitem(collector, name, obj): if not (isfunction(obj) or isfunction(get_real_func(obj))): filename, lineno = getfslineno(obj) warnings.warn_explicit( - message=PytestCollectionWarning( + message=PytestCollectionWarning( "cannot collect %r because it is not a function." % name ), category=None, @@ -226,10 +226,10 @@ def pytest_pycollect_makeitem(collector, name, obj): ) elif getattr(obj, "__test__", True): if is_generator(obj): - res = Function(name, parent=collector) - reason = deprecated.YIELD_TESTS.format(name=name) - res.add_marker(MARK_GEN.xfail(run=False, reason=reason)) - res.warn(PytestCollectionWarning(reason)) + res = Function(name, parent=collector) + reason = deprecated.YIELD_TESTS.format(name=name) + res.add_marker(MARK_GEN.xfail(run=False, reason=reason)) + res.warn(PytestCollectionWarning(reason)) else: res = list(collector._genfunctions(name, obj)) outcome.force_result(res) @@ -251,24 +251,24 @@ class PyobjMixin(PyobjContext): def __init__(self, *k, **kw): super(PyobjMixin, self).__init__(*k, **kw) - @property - def obj(self): - """Underlying Python object.""" - obj = getattr(self, "_obj", None) - if obj is None: - self._obj = obj = self._getobj() - # XXX evil hack - # used to avoid Instance collector marker duplication - if self._ALLOW_MARKERS: - self.own_markers.extend(get_unpacked_marks(self.obj)) - return obj - - @obj.setter - def obj(self, value): - self._obj = value + @property + def obj(self): + """Underlying Python object.""" + obj = getattr(self, "_obj", None) + if obj is None: + self._obj = obj = self._getobj() + # XXX evil hack + # used to avoid Instance collector marker duplication + if self._ALLOW_MARKERS: + self.own_markers.extend(get_unpacked_marks(self.obj)) + return obj + + @obj.setter + def obj(self, value): + self._obj = value def _getobj(self): - """Gets the underlying Python object. May be overwritten by subclasses.""" + """Gets the underlying Python object. May be overwritten by subclasses.""" return getattr(self.parent.obj, self.name) def getmodpath(self, stopatmodule=True, includemodule=False): @@ -440,66 +440,66 @@ class Module(nodes.File, PyCollector): return self._importtestmodule() def collect(self): - self._inject_setup_module_fixture() - self._inject_setup_function_fixture() + self._inject_setup_module_fixture() + self._inject_setup_function_fixture() self.session._fixturemanager.parsefactories(self) return super(Module, self).collect() - def _inject_setup_module_fixture(self): - """Injects a hidden autouse, module scoped fixture into the collected module object - that invokes setUpModule/tearDownModule if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_module = _get_non_fixture_func(self.obj, "setUpModule") - if setup_module is None: - setup_module = _get_non_fixture_func(self.obj, "setup_module") - - teardown_module = _get_non_fixture_func(self.obj, "tearDownModule") - if teardown_module is None: - teardown_module = _get_non_fixture_func(self.obj, "teardown_module") - - if setup_module is None and teardown_module is None: - return - - @fixtures.fixture(autouse=True, scope="module") - def xunit_setup_module_fixture(request): - if setup_module is not None: - _call_with_optional_argument(setup_module, request.module) - yield - if teardown_module is not None: - _call_with_optional_argument(teardown_module, request.module) - - self.obj.__pytest_setup_module = xunit_setup_module_fixture - - def _inject_setup_function_fixture(self): - """Injects a hidden autouse, function scoped fixture into the collected module object - that invokes setup_function/teardown_function if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_function = _get_non_fixture_func(self.obj, "setup_function") - teardown_function = _get_non_fixture_func(self.obj, "teardown_function") - if setup_function is None and teardown_function is None: - return - - @fixtures.fixture(autouse=True, scope="function") - def xunit_setup_function_fixture(request): - if request.instance is not None: - # in this case we are bound to an instance, so we need to let - # setup_method handle this - yield - return - if setup_function is not None: - _call_with_optional_argument(setup_function, request.function) - yield - if teardown_function is not None: - _call_with_optional_argument(teardown_function, request.function) - - self.obj.__pytest_setup_function = xunit_setup_function_fixture - + def _inject_setup_module_fixture(self): + """Injects a hidden autouse, module scoped fixture into the collected module object + that invokes setUpModule/tearDownModule if either or both are available. + + Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with + other fixtures (#517). + """ + setup_module = _get_non_fixture_func(self.obj, "setUpModule") + if setup_module is None: + setup_module = _get_non_fixture_func(self.obj, "setup_module") + + teardown_module = _get_non_fixture_func(self.obj, "tearDownModule") + if teardown_module is None: + teardown_module = _get_non_fixture_func(self.obj, "teardown_module") + + if setup_module is None and teardown_module is None: + return + + @fixtures.fixture(autouse=True, scope="module") + def xunit_setup_module_fixture(request): + if setup_module is not None: + _call_with_optional_argument(setup_module, request.module) + yield + if teardown_module is not None: + _call_with_optional_argument(teardown_module, request.module) + + self.obj.__pytest_setup_module = xunit_setup_module_fixture + + def _inject_setup_function_fixture(self): + """Injects a hidden autouse, function scoped fixture into the collected module object + that invokes setup_function/teardown_function if either or both are available. + + Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with + other fixtures (#517). + """ + setup_function = _get_non_fixture_func(self.obj, "setup_function") + teardown_function = _get_non_fixture_func(self.obj, "teardown_function") + if setup_function is None and teardown_function is None: + return + + @fixtures.fixture(autouse=True, scope="function") + def xunit_setup_function_fixture(request): + if request.instance is not None: + # in this case we are bound to an instance, so we need to let + # setup_method handle this + yield + return + if setup_function is not None: + _call_with_optional_argument(setup_function, request.function) + yield + if teardown_function is not None: + _call_with_optional_argument(teardown_function, request.function) + + self.obj.__pytest_setup_function = xunit_setup_function_fixture + def _importtestmodule(self): # we assume we are only called once per module importmode = self.config.getoption("--import-mode") @@ -507,7 +507,7 @@ class Module(nodes.File, PyCollector): mod = self.fspath.pyimport(ensuresyspath=importmode) except SyntaxError: raise self.CollectError( - _pytest._code.ExceptionInfo.from_current().getrepr(style="short") + _pytest._code.ExceptionInfo.from_current().getrepr(style="short") ) except self.fspath.ImportMismatchError: e = sys.exc_info()[1] @@ -523,7 +523,7 @@ class Module(nodes.File, PyCollector): except ImportError: from _pytest._code.code import ExceptionInfo - exc_info = ExceptionInfo.from_current() + exc_info = ExceptionInfo.from_current() if self.config.getoption("verbose") < 2: exc_info.traceback = exc_info.traceback.filter(filter_traceback) exc_repr = ( @@ -562,22 +562,22 @@ class Package(Module): self._norecursepatterns = session._norecursepatterns self.fspath = fspath - def setup(self): - # not using fixtures to call setup_module here because autouse fixtures - # from packages are not called automatically (#4085) - setup_module = _get_non_fixture_func(self.obj, "setUpModule") - if setup_module is None: - setup_module = _get_non_fixture_func(self.obj, "setup_module") - if setup_module is not None: - _call_with_optional_argument(setup_module, self.obj) - - teardown_module = _get_non_fixture_func(self.obj, "tearDownModule") - if teardown_module is None: - teardown_module = _get_non_fixture_func(self.obj, "teardown_module") - if teardown_module is not None: - func = partial(_call_with_optional_argument, teardown_module, self.obj) - self.addfinalizer(func) - + def setup(self): + # not using fixtures to call setup_module here because autouse fixtures + # from packages are not called automatically (#4085) + setup_module = _get_non_fixture_func(self.obj, "setUpModule") + if setup_module is None: + setup_module = _get_non_fixture_func(self.obj, "setup_module") + if setup_module is not None: + _call_with_optional_argument(setup_module, self.obj) + + teardown_module = _get_non_fixture_func(self.obj, "tearDownModule") + if teardown_module is None: + teardown_module = _get_non_fixture_func(self.obj, "teardown_module") + if teardown_module is not None: + func = partial(_call_with_optional_argument, teardown_module, self.obj) + self.addfinalizer(func) + def _recurse(self, dirpath): if dirpath.basename == "__pycache__": return False @@ -606,12 +606,12 @@ class Package(Module): return proxy def _collectfile(self, path, handle_dupes=True): - assert path.isfile(), "%r is not a file (isdir=%r, exists=%r, islink=%r)" % ( - path, - path.isdir(), - path.exists(), - path.islink(), - ) + assert path.isfile(), "%r is not a file (isdir=%r, exists=%r, islink=%r)" % ( + path, + path.isdir(), + path.exists(), + path.islink(), + ) ihook = self.gethookproxy(path) if not self.isinitpath(path): if ihook.pytest_ignore_collect(path=path, config=self.config): @@ -644,8 +644,8 @@ class Package(Module): pkg_prefixes = set() for path in this_path.visit(rec=self._recurse, bf=True, sort=True): # We will visit our own __init__.py file, in which case we skip it. - is_file = path.isfile() - if is_file: + is_file = path.isfile() + if is_file: if path.basename == "__init__.py" and path.dirpath() == this_path: continue @@ -656,13 +656,13 @@ class Package(Module): ): continue - if is_file: - for x in self._collectfile(path): - yield x - elif not path.isdir(): - # Broken symlink or invalid/missing file. - continue - elif path.join("__init__.py").check(file=1): + if is_file: + for x in self._collectfile(path): + yield x + elif not path.isdir(): + # Broken symlink or invalid/missing file. + continue + elif path.join("__init__.py").check(file=1): pkg_prefixes.add(path) @@ -674,9 +674,9 @@ def _get_xunit_setup_teardown(holder, attr_name, param_obj=None): when the callable is called without arguments, defaults to the ``holder`` object. Return ``None`` if a suitable callable is not found. """ - # TODO: only needed because of Package! + # TODO: only needed because of Package! param_obj = param_obj if param_obj is not None else holder - result = _get_non_fixture_func(holder, attr_name) + result = _get_non_fixture_func(holder, attr_name) if result is not None: arg_count = result.__code__.co_argcount if inspect.ismethod(result): @@ -687,19 +687,19 @@ def _get_xunit_setup_teardown(holder, attr_name, param_obj=None): return result -def _call_with_optional_argument(func, arg): - """Call the given function with the given argument if func accepts one argument, otherwise - calls func without arguments""" - arg_count = func.__code__.co_argcount - if inspect.ismethod(func): - arg_count -= 1 - if arg_count: - func(arg) - else: - func() - - -def _get_non_fixture_func(obj, name): +def _call_with_optional_argument(func, arg): + """Call the given function with the given argument if func accepts one argument, otherwise + calls func without arguments""" + arg_count = func.__code__.co_argcount + if inspect.ismethod(func): + arg_count -= 1 + if arg_count: + func(arg) + else: + func() + + +def _get_non_fixture_func(obj, name): """Return the attribute from the given object to be used as a setup/teardown xunit-style function, but only if not marked as a fixture to avoid calling it twice. @@ -717,78 +717,78 @@ class Class(PyCollector): return [] if hasinit(self.obj): self.warn( - PytestCollectionWarning( + PytestCollectionWarning( "cannot collect test class %r because it has a " - "__init__ constructor (from: %s)" - % (self.obj.__name__, self.parent.nodeid) + "__init__ constructor (from: %s)" + % (self.obj.__name__, self.parent.nodeid) ) ) return [] elif hasnew(self.obj): self.warn( - PytestCollectionWarning( + PytestCollectionWarning( "cannot collect test class %r because it has a " - "__new__ constructor (from: %s)" - % (self.obj.__name__, self.parent.nodeid) + "__new__ constructor (from: %s)" + % (self.obj.__name__, self.parent.nodeid) ) ) return [] - self._inject_setup_class_fixture() - self._inject_setup_method_fixture() - - return [Instance(name="()", parent=self)] - - def _inject_setup_class_fixture(self): - """Injects a hidden autouse, class scoped fixture into the collected class object - that invokes setup_class/teardown_class if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_class = _get_non_fixture_func(self.obj, "setup_class") - teardown_class = getattr(self.obj, "teardown_class", None) - if setup_class is None and teardown_class is None: - return - - @fixtures.fixture(autouse=True, scope="class") - def xunit_setup_class_fixture(cls): - if setup_class is not None: - func = getimfunc(setup_class) - _call_with_optional_argument(func, self.obj) - yield - if teardown_class is not None: - func = getimfunc(teardown_class) - _call_with_optional_argument(func, self.obj) - - self.obj.__pytest_setup_class = xunit_setup_class_fixture - - def _inject_setup_method_fixture(self): - """Injects a hidden autouse, function scoped fixture into the collected class object - that invokes setup_method/teardown_method if either or both are available. - - Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with - other fixtures (#517). - """ - setup_method = _get_non_fixture_func(self.obj, "setup_method") - teardown_method = getattr(self.obj, "teardown_method", None) - if setup_method is None and teardown_method is None: - return - - @fixtures.fixture(autouse=True, scope="function") - def xunit_setup_method_fixture(self, request): - method = request.function - if setup_method is not None: - func = getattr(self, "setup_method") - _call_with_optional_argument(func, method) - yield - if teardown_method is not None: - func = getattr(self, "teardown_method") - _call_with_optional_argument(func, method) - - self.obj.__pytest_setup_method = xunit_setup_method_fixture - - + self._inject_setup_class_fixture() + self._inject_setup_method_fixture() + + return [Instance(name="()", parent=self)] + + def _inject_setup_class_fixture(self): + """Injects a hidden autouse, class scoped fixture into the collected class object + that invokes setup_class/teardown_class if either or both are available. + + Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with + other fixtures (#517). + """ + setup_class = _get_non_fixture_func(self.obj, "setup_class") + teardown_class = getattr(self.obj, "teardown_class", None) + if setup_class is None and teardown_class is None: + return + + @fixtures.fixture(autouse=True, scope="class") + def xunit_setup_class_fixture(cls): + if setup_class is not None: + func = getimfunc(setup_class) + _call_with_optional_argument(func, self.obj) + yield + if teardown_class is not None: + func = getimfunc(teardown_class) + _call_with_optional_argument(func, self.obj) + + self.obj.__pytest_setup_class = xunit_setup_class_fixture + + def _inject_setup_method_fixture(self): + """Injects a hidden autouse, function scoped fixture into the collected class object + that invokes setup_method/teardown_method if either or both are available. + + Using a fixture to invoke this methods ensures we play nicely and unsurprisingly with + other fixtures (#517). + """ + setup_method = _get_non_fixture_func(self.obj, "setup_method") + teardown_method = getattr(self.obj, "teardown_method", None) + if setup_method is None and teardown_method is None: + return + + @fixtures.fixture(autouse=True, scope="function") + def xunit_setup_method_fixture(self, request): + method = request.function + if setup_method is not None: + func = getattr(self, "setup_method") + _call_with_optional_argument(func, method) + yield + if teardown_method is not None: + func = getattr(self, "teardown_method") + _call_with_optional_argument(func, method) + + self.obj.__pytest_setup_method = xunit_setup_method_fixture + + class Instance(PyCollector): _ALLOW_MARKERS = False # hack, destroy later # instances share the object with their parents in a way @@ -813,12 +813,12 @@ class FunctionMixin(PyobjMixin): def setup(self): """ perform setup for this test function. """ - if isinstance(self.parent, Instance): - self.parent.newinstance() + if isinstance(self.parent, Instance): + self.parent.newinstance() self.obj = self._getobj() def _prunetraceback(self, excinfo): - if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False): + if hasattr(self, "_obj") and not self.config.getoption("fulltrace", False): code = _pytest._code.Code(get_real_func(self.obj)) path, firstlineno = code.path, code.firstlineno traceback = excinfo.traceback @@ -833,14 +833,14 @@ class FunctionMixin(PyobjMixin): excinfo.traceback = ntraceback.filter() # issue364: mark all but first and last frames to # only show a single-line message for each frame - if self.config.getoption("tbstyle", "auto") == "auto": + if self.config.getoption("tbstyle", "auto") == "auto": if len(excinfo.traceback) > 2: for entry in excinfo.traceback[1:-1]: entry.set_repr_style("short") def repr_failure(self, excinfo, outerr=None): assert outerr is None, "XXX outerr usage is deprecated" - style = self.config.getoption("tbstyle", "auto") + style = self.config.getoption("tbstyle", "auto") if style == "auto": style = "long" return self._repr_failure_py(excinfo, style=style) @@ -1048,7 +1048,7 @@ class Metafunc(fixtures.FuncargnamesCompatAttr): :rtype: List[str] :return: the list of ids for each argname given """ - from _pytest._io.saferepr import saferepr + from _pytest._io.saferepr import saferepr idfn = None if callable(ids): @@ -1161,30 +1161,30 @@ def _find_parametrized_scope(argnames, arg2fixturedefs, indirect): return "function" -def _ascii_escaped_by_config(val, config): - if config is None: - escape_option = False - else: - escape_option = config.getini( - "disable_test_id_escaping_and_forfeit_all_rights_to_community_support" - ) - return val if escape_option else ascii_escaped(val) - - +def _ascii_escaped_by_config(val, config): + if config is None: + escape_option = False + else: + escape_option = config.getini( + "disable_test_id_escaping_and_forfeit_all_rights_to_community_support" + ) + return val if escape_option else ascii_escaped(val) + + def _idval(val, argname, idx, idfn, item, config): if idfn: try: - generated_id = idfn(val) - if generated_id is not None: - val = generated_id + generated_id = idfn(val) + if generated_id is not None: + val = generated_id except Exception as e: # See issue https://github.com/pytest-dev/pytest/issues/2169 - msg = "{}: error raised while trying to determine id of parameter '{}' at position {}\n" - msg = msg.format(item.nodeid, argname, idx) - # we only append the exception type and message because on Python 2 reraise does nothing + msg = "{}: error raised while trying to determine id of parameter '{}' at position {}\n" + msg = msg.format(item.nodeid, argname, idx) + # we only append the exception type and message because on Python 2 reraise does nothing msg += " {}: {}\n".format(type(e).__name__, e) - six.raise_from(ValueError(msg), e) - elif config: + six.raise_from(ValueError(msg), e) + elif config: hook_id = config.hook.pytest_make_parametrize_id( config=config, val=val, argname=argname ) @@ -1192,8 +1192,8 @@ def _idval(val, argname, idx, idfn, item, config): return hook_id if isinstance(val, STRING_TYPES): - return _ascii_escaped_by_config(val, config) - elif val is None or isinstance(val, (float, int, bool)): + return _ascii_escaped_by_config(val, config) + elif val is None or isinstance(val, (float, int, bool)): return str(val) elif isinstance(val, REGEX_TYPE): return ascii_escaped(val.pattern) @@ -1218,10 +1218,10 @@ def limit_idval(limit): if len(idval) > limit: prefix = idval[:limit] # There might be same prefix for the different test cases - take item into account - name = "{}-{}".format(kw.get('item', ''), safe_str(prefix)) + name = "{}-{}".format(kw.get('item', ''), safe_str(prefix)) idx = names.setdefault(name, -1) + 1 names[name] = idx - idval = "{}-{}".format(safe_str(prefix), idx) + idval = "{}-{}".format(safe_str(prefix), idx) return idval return wrapper @@ -1241,7 +1241,7 @@ def _idvalset(idx, parameterset, argnames, idfn, ids, item, config): ] return "-".join(this_id) else: - return _ascii_escaped_by_config(ids[idx], config) + return _ascii_escaped_by_config(ids[idx], config) def idmaker(argnames, parametersets, idfn=None, ids=None, config=None, item=None): @@ -1366,22 +1366,22 @@ def _showfixtures_main(config, session): currentmodule = module if verbose <= 0 and argname[0] == "_": continue - tw.write(argname, green=True) - if fixturedef.scope != "function": - tw.write(" [%s scope]" % fixturedef.scope, cyan=True) + tw.write(argname, green=True) + if fixturedef.scope != "function": + tw.write(" [%s scope]" % fixturedef.scope, cyan=True) if verbose > 0: - tw.write(" -- %s" % bestrel, yellow=True) - tw.write("\n") + tw.write(" -- %s" % bestrel, yellow=True) + tw.write("\n") loc = getlocation(fixturedef.func, curdir) doc = fixturedef.func.__doc__ or "" if doc: write_docstring(tw, doc) else: tw.line(" %s: no docstring available" % (loc,), red=True) - tw.line() + tw.line() -def write_docstring(tw, doc, indent=" "): +def write_docstring(tw, doc, indent=" "): doc = doc.rstrip() if "\n" in doc: firstline, rest = doc.split("\n", 1) @@ -1389,11 +1389,11 @@ def write_docstring(tw, doc, indent=" "): firstline, rest = doc, "" if firstline.strip(): - tw.line(indent + firstline.strip()) + tw.line(indent + firstline.strip()) if rest: for line in dedent(rest).split("\n"): - tw.write(indent + line + "\n") + tw.write(indent + line + "\n") class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): @@ -1437,23 +1437,23 @@ class Function(FunctionMixin, nodes.Item, fixtures.FuncargnamesCompatAttr): if keywords: self.keywords.update(keywords) - # todo: this is a hell of a hack - # https://github.com/pytest-dev/pytest/issues/4569 - - self.keywords.update( - dict.fromkeys( - [ - mark.name - for mark in self.iter_markers() - if mark.name not in self.keywords - ], - True, - ) - ) - + # todo: this is a hell of a hack + # https://github.com/pytest-dev/pytest/issues/4569 + + self.keywords.update( + dict.fromkeys( + [ + mark.name + for mark in self.iter_markers() + if mark.name not in self.keywords + ], + True, + ) + ) + if fixtureinfo is None: fixtureinfo = self.session._fixturemanager.getfixtureinfo( - self, self.obj, self.cls, funcargs=True + self, self.obj, self.cls, funcargs=True ) self._fixtureinfo = fixtureinfo self.fixturenames = fixtureinfo.names_closure |