diff options
author | danila-eremin <danila-eremin@yandex-team.ru> | 2022-02-10 16:46:21 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:21 +0300 |
commit | 358e631d1a69242d3ae4d6e6b1e4f7581d03133b (patch) | |
tree | db997f29fd5f1b32ede8ce681a7c73ec0a0714d0 /library/python/pytest/plugins/collection.py | |
parent | bf23f1e45d4627b54a70900ef362c1be748cc787 (diff) | |
download | ydb-358e631d1a69242d3ae4d6e6b1e4f7581d03133b.tar.gz |
Restoring authorship annotation for <danila-eremin@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/pytest/plugins/collection.py')
-rw-r--r-- | library/python/pytest/plugins/collection.py | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index e36f47a78f..9c29494de8 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -12,40 +12,40 @@ import library.python.testing.filter.filter as test_filter class LoadedModule(_pytest.python.Module): - def __init__(self, parent, name, **kwargs): - self.name = name + '.py' - self.session = parent - self.parent = parent - self.config = parent.config + def __init__(self, parent, name, **kwargs): + self.name = name + '.py' + self.session = parent + self.parent = parent + self.config = parent.config self.keywords = {} 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 - - return loaded_module - + 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 + + return loaded_module + @property - def _nodeid(self): - if os.getenv('CONFTEST_LOAD_POLICY') == 'LOCAL': + def _nodeid(self): + if os.getenv('CONFTEST_LOAD_POLICY') == 'LOCAL': return self._getobj().__file__ else: return self.name - - @property - def nodeid(self): - return self._nodeid + + @property + def nodeid(self): + return self._nodeid def _getobj(self): - module_name = self.name[:-len('.py')] + module_name = self.name[:-len('.py')] if self.namespace: - module_name = '__tests__.' + module_name + module_name = '__tests__.' + module_name __import__(module_name) return sys.modules[module_name] @@ -62,19 +62,19 @@ class DoctestModule(LoadedModule): runner = doctest.DebugRunner(verbose=0, optionflags=optionflags) try: - for test in finder.find(module, self.name[:-len('.py')]): + for test in finder.find(module, self.name[:-len('.py')]): if test.examples: # skip empty doctests - yield getattr(_pytest.doctest.DoctestItem, 'from_parent', _pytest.doctest.DoctestItem)( - name=test.name, - parent=self, - runner=runner, - dtest=test) + yield getattr(_pytest.doctest.DoctestItem, 'from_parent', _pytest.doctest.DoctestItem)( + name=test.name, + parent=self, + runner=runner, + dtest=test) except Exception: import logging logging.exception('DoctestModule failed, probably you can add NO_DOCTESTS() macro to ya.make') etype, exc, tb = sys.exc_info() msg = 'DoctestModule failed, probably you can add NO_DOCTESTS() macro to ya.make' - reraise(etype, type(exc)('{}\n{}'.format(exc, msg)), tb) + reraise(etype, type(exc)('{}\n{}'.format(exc, msg)), tb) # NOTE: Since we are overriding collect method of pytest session, pytest hooks are not invoked during collection. @@ -88,7 +88,7 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f test_file_filter = getattr(session.config.option, 'test_file_filter', None) if test_file_filter is None: return False - if module.name != test_file_filter.replace('/', '.'): + if module.name != test_file_filter.replace('/', '.'): return True return False @@ -112,17 +112,17 @@ class CollectionPlugin(object): filenames_filter = set(map(lambda x: x.split('::')[0], full_names_filter)) for test_module in self._test_modules: - module = LoadedModule.from_parent(name=test_module, parent=session) + module = LoadedModule.from_parent(name=test_module, parent=session) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): yield module if os.environ.get('YA_PYTEST_DISABLE_DOCTEST', 'no') == 'no': - module = DoctestModule.from_parent(name=test_module, parent=session) + module = DoctestModule.from_parent(name=test_module, parent=session) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): yield module 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) + yield DoctestModule.from_parent(name=doctest_module, parent=session, namespace=False) session.collect = collect |