diff options
| author | deshevoy <[email protected]> | 2022-02-10 16:46:56 +0300 | 
|---|---|---|
| committer | Daniil Cherednik <[email protected]> | 2022-02-10 16:46:56 +0300 | 
| commit | e988f30484abe5fdeedcc7a5d3c226c01a21800c (patch) | |
| tree | 0a217b173aabb57b7e51f8a169989b1a3e0309fe /library/python/pytest | |
| parent | 33ee501c05d3f24036ae89766a858930ae66c548 (diff) | |
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/python/pytest')
| -rw-r--r-- | library/python/pytest/main.py | 38 | ||||
| -rw-r--r-- | library/python/pytest/plugins/collection.py | 20 | ||||
| -rw-r--r-- | library/python/pytest/plugins/conftests.py | 22 | ||||
| -rw-r--r-- | library/python/pytest/plugins/ya.py | 38 | ||||
| -rw-r--r-- | library/python/pytest/pytest.yatest.ini | 6 | ||||
| -rw-r--r-- | library/python/pytest/rewrite.py | 128 | ||||
| -rw-r--r-- | library/python/pytest/ya.make | 2 | ||||
| -rw-r--r-- | library/python/pytest/yatest_tools.py | 8 | 
8 files changed, 131 insertions, 131 deletions
| diff --git a/library/python/pytest/main.py b/library/python/pytest/main.py index 6296bd6f0fa..355623ff0e3 100644 --- a/library/python/pytest/main.py +++ b/library/python/pytest/main.py @@ -2,10 +2,10 @@ import os  import sys  import time -import __res +import __res   FORCE_EXIT_TESTSFAILED_ENV = 'FORCE_EXIT_TESTSFAILED' - +   def main():      import library.python.pytest.context as context @@ -39,12 +39,12 @@ def main():      import library.python.pytest.plugins.ya as ya      import library.python.pytest.plugins.conftests as conftests -    import _pytest.assertion -    from _pytest.monkeypatch import MonkeyPatch +    import _pytest.assertion  +    from _pytest.monkeypatch import MonkeyPatch       from . import rewrite -    m = MonkeyPatch() -    m.setattr(_pytest.assertion.rewrite, "AssertionRewritingHook", rewrite.AssertionRewritingHook) - +    m = MonkeyPatch()  +    m.setattr(_pytest.assertion.rewrite, "AssertionRewritingHook", rewrite.AssertionRewritingHook)  +       prefix = '__tests__.'      test_modules = [ @@ -56,18 +56,18 @@ def main():      if isinstance(doctest_packages, bytes):          doctest_packages = doctest_packages.decode('utf-8')      doctest_packages = doctest_packages.split() - -    def is_doctest_module(name): -        for package in doctest_packages: +  +    def is_doctest_module(name):  +        for package in doctest_packages:               if name == package or name.startswith(str(package) + "."): -                return True -        return False - -    doctest_modules = [ -        name for name in sys.extra_modules -        if is_doctest_module(name) -    ] - +                return True  +        return False  +  +    doctest_modules = [  +        name for name in sys.extra_modules  +        if is_doctest_module(name)  +    ]  +       def remove_user_site(paths):          site_paths = ('site-packages', 'site-python') @@ -86,7 +86,7 @@ def main():      sys.path = remove_user_site(sys.path)      rc = pytest.main(plugins=[ -        collection.CollectionPlugin(test_modules, doctest_modules), +        collection.CollectionPlugin(test_modules, doctest_modules),           ya,          conftests,      ]) diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index e36f47a78f3..dad830e4736 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -18,14 +18,14 @@ class LoadedModule(_pytest.python.Module):          self.parent = parent          self.config = parent.config          self.keywords = {} -        self.own_markers = [] +        self.own_markers = []           self.fspath = py.path.local()      @classmethod      def from_parent(cls, **kwargs):          namespace = kwargs.pop('namespace', True)          kwargs.setdefault('fspath', py.path.local()) - +           loaded_module = getattr(super(LoadedModule, cls), 'from_parent', cls)(**kwargs)          loaded_module.namespace = namespace @@ -44,7 +44,7 @@ class LoadedModule(_pytest.python.Module):      def _getobj(self):          module_name = self.name[:-len('.py')] -        if self.namespace: +        if self.namespace:               module_name = '__tests__.' + module_name          __import__(module_name)          return sys.modules[module_name] @@ -54,13 +54,13 @@ class DoctestModule(LoadedModule):      def collect(self):          import doctest - -        module = self._getobj() -        # uses internal doctest module parsing mechanism +  +        module = self._getobj()  +        # uses internal doctest module parsing mechanism           finder = doctest.DocTestFinder()          optionflags = _pytest.doctest.get_optionflags(self)          runner = doctest.DebugRunner(verbose=0, optionflags=optionflags) - +           try:              for test in finder.find(module, self.name[:-len('.py')]):                  if test.examples:  # skip empty doctests @@ -94,9 +94,9 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f  class CollectionPlugin(object): -    def __init__(self, test_modules, doctest_modules): +    def __init__(self, test_modules, doctest_modules):           self._test_modules = test_modules -        self._doctest_modules = doctest_modules +        self._doctest_modules = doctest_modules       def pytest_sessionstart(self, session): @@ -124,5 +124,5 @@ class CollectionPlugin(object):              if os.environ.get('YA_PYTEST_DISABLE_DOCTEST', 'no') == 'no':                  for doctest_module in self._doctest_modules:                      yield DoctestModule.from_parent(name=doctest_module, parent=session, namespace=False) - +           session.collect = collect diff --git a/library/python/pytest/plugins/conftests.py b/library/python/pytest/plugins/conftests.py index 522041f5a7c..96456da28c8 100644 --- a/library/python/pytest/plugins/conftests.py +++ b/library/python/pytest/plugins/conftests.py @@ -23,23 +23,23 @@ conftest_modules = []  @hookimpl(trylast=True)  def pytest_load_initial_conftests(early_config, parser, args): -    conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules) +    conftests = filter(lambda name: name.endswith(".conftest"), sys.extra_modules)  -    def conftest_key(name): -        if not name.startswith("__tests__."): -            # Make __tests__ come last -            return "_." + name -        return name +    def conftest_key(name):  +        if not name.startswith("__tests__."):  +            # Make __tests__ come last  +            return "_." + name  +        return name  -    for name in sorted(conftests, key=conftest_key): -        mod = importlib.import_module(name) +    for name in sorted(conftests, key=conftest_key):  +        mod = importlib.import_module(name)           if os.getenv("CONFTEST_LOAD_POLICY") != "LOCAL":              mod.__orig_file__ = mod.__file__              mod.__file__ = "" -        conftest_modules.append(mod) +        conftest_modules.append(mod)           early_config.pluginmanager.consider_conftest(mod) - - +  +   def getconftestmodules(*args, **kwargs):      return conftest_modules diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py index 1bde03042d4..0dfbb7c2748 100644 --- a/library/python/pytest/plugins/ya.py +++ b/library/python/pytest/plugins/ya.py @@ -185,7 +185,7 @@ def pytest_configure(config):      global pytest_config      pytest_config = config -    config.option.continue_on_collection_errors = True +    config.option.continue_on_collection_errors = True       config.addinivalue_line("markers", "ya:external") @@ -523,9 +523,9 @@ def pytest_collectreport(report):              sys.stderr.write(yatest_lib.tools.to_utf8(report.longrepr)) -def pytest_pyfunc_call(pyfuncitem): -    testfunction = pyfuncitem.obj +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" @@ -538,9 +538,9 @@ def pytest_pyfunc_call(pyfuncitem):      funcargs = pyfuncitem.funcargs      testargs = {arg: funcargs[arg] for arg in pyfuncitem._fixtureinfo.argnames}      pyfuncitem.retval = testfunction(**testargs) -    return True - - +    return True  +  +   @pytest.hookimpl(hookwrapper=True)  def pytest_runtest_makereport(item, call):      def logreport(report, result, call): @@ -575,8 +575,8 @@ def pytest_runtest_makereport(item, call):      outcome = yield      rep = outcome.get_result()      result = None -    if hasattr(item, 'retval') and item.retval is not None: -        result = item.retval +    if hasattr(item, 'retval') and item.retval is not None:  +        result = item.retval           if not pytest_config.from_ya_test:              ti = TestItem(rep, result, pytest_config.option.test_suffix)              tr = pytest_config.pluginmanager.getplugin('terminalreporter') @@ -584,13 +584,13 @@ def pytest_runtest_makereport(item, call):      logreport(rep, result, call) -def pytest_make_parametrize_id(config, val, argname): -    # Avoid <, > symbols in canondata file names -    if inspect.isfunction(val) and val.__name__ == "<lambda>": -        return str(argname) -    return None - - +def pytest_make_parametrize_id(config, val, argname):  +    # Avoid <, > symbols in canondata file names  +    if inspect.isfunction(val) and val.__name__ == "<lambda>":  +        return str(argname)  +    return None  +  +   def get_formatted_error(report):      if isinstance(report.longrepr, tuple):          text = "" @@ -692,7 +692,7 @@ class TestItem(object):          return self._error      def set_error(self, entry, marker='bad'): -        if isinstance(entry, _pytest.reports.BaseReport): +        if isinstance(entry, _pytest.reports.BaseReport):               self._error = get_formatted_error(entry)          else:              self._error = "[[{}]]{}".format(yatest_lib.tools.to_str(marker), yatest_lib.tools.to_str(entry)) @@ -827,9 +827,9 @@ class TraceReportGenerator(object):          self.trace('subtest-started', message)      def on_finish_test_case(self, test_item, duration_only=False): -        if test_item.result is not None: +        if test_item.result is not None:               try: -                result = canon.serialize(test_item.result) +                result = canon.serialize(test_item.result)               except Exception as e:                  yatest_logger.exception("Error while serializing test results")                  test_item.set_error("Invalid test result: {}".format(e)) diff --git a/library/python/pytest/pytest.yatest.ini b/library/python/pytest/pytest.yatest.ini index 70d6c98516e..b755a300f91 100644 --- a/library/python/pytest/pytest.yatest.ini +++ b/library/python/pytest/pytest.yatest.ini @@ -2,6 +2,6 @@  pep8maxlinelength = 200  norecursedirs = *  pep8ignore = E127 E123 E226 E24 -filterwarnings = -    ignore::pytest.RemovedInPytest4Warning -addopts = -p no:warnings +filterwarnings =  +    ignore::pytest.RemovedInPytest4Warning  +addopts = -p no:warnings  diff --git a/library/python/pytest/rewrite.py b/library/python/pytest/rewrite.py index 4cebcb1edd9..e14bd3279b2 100644 --- a/library/python/pytest/rewrite.py +++ b/library/python/pytest/rewrite.py @@ -1,11 +1,11 @@ -from __future__ import absolute_import -from __future__ import print_function - -import ast - +from __future__ import absolute_import  +from __future__ import print_function  +  +import ast  +   import py -from _pytest.assertion import rewrite +from _pytest.assertion import rewrite   try:      import importlib.util  except ImportError: @@ -16,23 +16,23 @@ try:  except ImportError:      pass -from __res import importer +from __res import importer   import sys  import six - - +  +   def _get_state(config):      if hasattr(config, '_assertstate'):          return config._assertstate      return config._store[rewrite.assertstate_key] -class AssertionRewritingHook(rewrite.AssertionRewritingHook): +class AssertionRewritingHook(rewrite.AssertionRewritingHook):       def __init__(self, *args, **kwargs):          self.modules = {}          super(AssertionRewritingHook, self).__init__(*args, **kwargs) - -    def find_module(self, name, path=None): +  +    def find_module(self, name, path=None):           co = self._find_module(name, path)          if co is not None:              return self @@ -40,28 +40,28 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):      def _find_module(self, name, path=None):          state = _get_state(self.config)          if not self._should_rewrite(name, None, state): -            return None -        state.trace("find_module called for: %s" % name) - -        try: -            if self.is_package(name): -                return None -        except ImportError: -            return None - +            return None  +        state.trace("find_module called for: %s" % name)  +  +        try:  +            if self.is_package(name):  +                return None  +        except ImportError:  +            return None  +           if hasattr(self._rewritten_names, 'add'):              self._rewritten_names.add(name)          else:              self._rewritten_names[name] = Path(path[0]) - -        state.trace("rewriting %s" % name) -        co = _rewrite_test(self.config, name) -        if co is None: -            # Probably a SyntaxError in the test. -            return None -        self.modules[name] = co, None +  +        state.trace("rewriting %s" % name)  +        co = _rewrite_test(self.config, name)  +        if co is None:  +            # Probably a SyntaxError in the test.  +            return None  +        self.modules[name] = co, None           return co - +       def find_spec(self, name, path=None, target=None):          co = self._find_module(name, path)          if co is not None: @@ -72,17 +72,17 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):          )      def _should_rewrite(self, name, fn, state): -        if name.startswith("__tests__.") or name.endswith(".conftest"): -            return True - -        return self._is_marked_for_rewrite(name, state) - -    def is_package(self, name): -        return importer.is_package(name) - -    def get_source(self, name): -        return importer.get_source(name) - +        if name.startswith("__tests__.") or name.endswith(".conftest"):  +            return True  +  +        return self._is_marked_for_rewrite(name, state)  +  +    def is_package(self, name):  +        return importer.is_package(name)  +  +    def get_source(self, name):  +        return importer.get_source(name)  +       if six.PY3:          def load_module(self, module):              co, _ = self.modules.pop(module.__name__) @@ -97,7 +97,7 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):                      del sys.modules[module.__name__]                  raise              return sys.modules[module.__name__] - +           def exec_module(self, module):              if module.__name__ in self.modules:                  self.load_module(module) @@ -105,28 +105,28 @@ class AssertionRewritingHook(rewrite.AssertionRewritingHook):                  super(AssertionRewritingHook, self).exec_module(module) -def _rewrite_test(config, name): -    """Try to read and rewrite *fn* and return the code object.""" +def _rewrite_test(config, name):  +    """Try to read and rewrite *fn* and return the code object."""       state = _get_state(config) - -    source = importer.get_source(name) -    if source is None: -        return None - -    path = importer.get_filename(name) - -    try: -        tree = ast.parse(source, filename=path) -    except SyntaxError: -        # Let this pop up again in the real import. -        state.trace("failed to parse: %r" % (path,)) -        return None +  +    source = importer.get_source(name)  +    if source is None:  +        return None  +  +    path = importer.get_filename(name)  +  +    try:  +        tree = ast.parse(source, filename=path)  +    except SyntaxError:  +        # Let this pop up again in the real import.  +        state.trace("failed to parse: %r" % (path,))  +        return None       rewrite.rewrite_asserts(tree, py.path.local(path), config) -    try: -        co = compile(tree, path, "exec", dont_inherit=True) -    except SyntaxError: -        # It's possible that this error is from some bug in the -        # assertion rewriting, but I don't know of a fast way to tell. -        state.trace("failed to compile: %r" % (path,)) -        return None -    return co +    try:  +        co = compile(tree, path, "exec", dont_inherit=True)  +    except SyntaxError:  +        # It's possible that this error is from some bug in the  +        # assertion rewriting, but I don't know of a fast way to tell.  +        state.trace("failed to compile: %r" % (path,))  +        return None  +    return co  diff --git a/library/python/pytest/ya.make b/library/python/pytest/ya.make index 060c92c3139..84c09543113 100644 --- a/library/python/pytest/ya.make +++ b/library/python/pytest/ya.make @@ -8,7 +8,7 @@ OWNER(  PY_SRCS(      __init__.py      main.py -    rewrite.py +    rewrite.py       yatest_tools.py      context.py  ) diff --git a/library/python/pytest/yatest_tools.py b/library/python/pytest/yatest_tools.py index 6b8b8963942..473bfeaadd6 100644 --- a/library/python/pytest/yatest_tools.py +++ b/library/python/pytest/yatest_tools.py @@ -284,10 +284,10 @@ def get_test_log_file_path(output_dir, class_name, test_name, extension="log"):  def split_node_id(nodeid, test_suffix=None): -    path, possible_open_bracket, params = nodeid.partition('[') +    path, possible_open_bracket, params = nodeid.partition('[')       separator = "::" -    if separator in path: -        path, test_name = path.split(separator, 1) +    if separator in path:  +        path, test_name = path.split(separator, 1)       else:          test_name = os.path.basename(path)      if test_suffix: @@ -300,5 +300,5 @@ def split_node_id(nodeid, test_suffix=None):              class_name += separator + klass_name      if separator in test_name:          test_name = test_name.split(separator)[-1] -    test_name += possible_open_bracket + params +    test_name += possible_open_bracket + params       return yatest_lib.tools.to_utf8(class_name), yatest_lib.tools.to_utf8(test_name) | 
