diff options
author | Dmitry Kopylov <kopylovd@gmail.com> | 2022-02-10 16:48:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:18 +0300 |
commit | b2f5101486cc0de2e979c8ba9ada2109785bf5fd (patch) | |
tree | affe28b840816b505db0467f2285b01c89c04247 /library/python/pytest/plugins/collection.py | |
parent | e9b28b5aad71453a4637b70dde02e801e4147a2a (diff) | |
download | ydb-b2f5101486cc0de2e979c8ba9ada2109785bf5fd.tar.gz |
Restoring authorship annotation for Dmitry Kopylov <kopylovd@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/python/pytest/plugins/collection.py')
-rw-r--r-- | library/python/pytest/plugins/collection.py | 70 |
1 files changed, 35 insertions, 35 deletions
diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index e36f47a78f..1535da686c 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -1,26 +1,26 @@ import os -import sys +import sys from six import reraise - -import py + +import py import pytest # noqa -import _pytest.python -import _pytest.doctest +import _pytest.python +import _pytest.doctest import json import library.python.testing.filter.filter as test_filter - - -class LoadedModule(_pytest.python.Module): + + +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 - self.keywords = {} + self.keywords = {} self.own_markers = [] self.fspath = py.path.local() - + @classmethod def from_parent(cls, **kwargs): namespace = kwargs.pop('namespace', True) @@ -31,7 +31,7 @@ class LoadedModule(_pytest.python.Module): return loaded_module - @property + @property def _nodeid(self): if os.getenv('CONFTEST_LOAD_POLICY') == 'LOCAL': return self._getobj().__file__ @@ -41,25 +41,25 @@ class LoadedModule(_pytest.python.Module): @property def nodeid(self): return self._nodeid - - def _getobj(self): + + def _getobj(self): module_name = self.name[:-len('.py')] if self.namespace: module_name = '__tests__.' + module_name - __import__(module_name) - return sys.modules[module_name] - - -class DoctestModule(LoadedModule): - - def collect(self): - import doctest + __import__(module_name) + return sys.modules[module_name] + + +class DoctestModule(LoadedModule): + + def collect(self): + import doctest 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) + 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')]): @@ -75,8 +75,8 @@ class DoctestModule(LoadedModule): 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) - - + + # NOTE: Since we are overriding collect method of pytest session, pytest hooks are not invoked during collection. def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_filename_predicate): if session.config.option.mode == 'list': @@ -93,14 +93,14 @@ def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_f return False -class CollectionPlugin(object): +class CollectionPlugin(object): def __init__(self, test_modules, doctest_modules): - self._test_modules = test_modules + self._test_modules = test_modules self._doctest_modules = doctest_modules - - def pytest_sessionstart(self, session): - - def collect(*args, **kwargs): + + def pytest_sessionstart(self, session): + + def collect(*args, **kwargs): accept_filename_predicate = test_filter.make_py_file_filter(session.config.option.test_filter) full_test_names_file_path = session.config.option.test_list_path filenames_filter = None @@ -111,7 +111,7 @@ class CollectionPlugin(object): full_names_filter = set(json.load(afile)[int(session.config.option.modulo_index)]) filenames_filter = set(map(lambda x: x.split('::')[0], full_names_filter)) - for test_module in self._test_modules: + for test_module in self._test_modules: module = LoadedModule.from_parent(name=test_module, parent=session) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): yield module @@ -120,9 +120,9 @@ class CollectionPlugin(object): 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) - session.collect = collect + session.collect = collect |