diff options
author | iaz1607 <iaz1607@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
commit | e5437feb4ac2d2dc044e1090b9312dde5ef197e0 (patch) | |
tree | f5a238c69dd20a1fa2092127a31b8aff25020f7d /library/python/pytest | |
parent | f4945d0a44b8770f0801de3056aa41639b0b7bd2 (diff) | |
download | ydb-e5437feb4ac2d2dc044e1090b9312dde5ef197e0.tar.gz |
Restoring authorship annotation for <iaz1607@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/python/pytest')
-rw-r--r-- | library/python/pytest/context.py | 2 | ||||
-rw-r--r-- | library/python/pytest/main.py | 8 | ||||
-rw-r--r-- | library/python/pytest/plugins/collection.py | 42 | ||||
-rw-r--r-- | library/python/pytest/plugins/ya.make | 2 | ||||
-rw-r--r-- | library/python/pytest/plugins/ya.py | 110 | ||||
-rw-r--r-- | library/python/pytest/ya.make | 2 |
6 files changed, 83 insertions, 83 deletions
diff --git a/library/python/pytest/context.py b/library/python/pytest/context.py index bfcdae50b5..be1b8854ae 100644 --- a/library/python/pytest/context.py +++ b/library/python/pytest/context.py @@ -1 +1 @@ -Ctx = {} +Ctx = {} diff --git a/library/python/pytest/main.py b/library/python/pytest/main.py index 6296bd6f0f..c9e0cdf48e 100644 --- a/library/python/pytest/main.py +++ b/library/python/pytest/main.py @@ -1,6 +1,6 @@ import os import sys -import time +import time import __res @@ -8,9 +8,9 @@ FORCE_EXIT_TESTSFAILED_ENV = 'FORCE_EXIT_TESTSFAILED' def main(): - import library.python.pytest.context as context - context.Ctx["YA_PYTEST_START_TIMESTAMP"] = time.time() - + import library.python.pytest.context as context + context.Ctx["YA_PYTEST_START_TIMESTAMP"] = time.time() + profile = None if '--profile-pytest' in sys.argv: sys.argv.remove('--profile-pytest') diff --git a/library/python/pytest/plugins/collection.py b/library/python/pytest/plugins/collection.py index e36f47a78f..86e0d68a9b 100644 --- a/library/python/pytest/plugins/collection.py +++ b/library/python/pytest/plugins/collection.py @@ -7,8 +7,8 @@ import py import pytest # noqa import _pytest.python import _pytest.doctest -import json -import library.python.testing.filter.filter as test_filter +import json +import library.python.testing.filter.filter as test_filter class LoadedModule(_pytest.python.Module): @@ -78,13 +78,13 @@ class DoctestModule(LoadedModule): # 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': - return not accept_filename_predicate(module.name) - - if filenames_from_full_filters is not None and module.name not in filenames_from_full_filters: - return True - +def pytest_ignore_collect(module, session, filenames_from_full_filters, accept_filename_predicate): + if session.config.option.mode == 'list': + return not accept_filename_predicate(module.name) + + if filenames_from_full_filters is not None and module.name not in filenames_from_full_filters: + return True + test_file_filter = getattr(session.config.option, 'test_file_filter', None) if test_file_filter is None: return False @@ -101,21 +101,21 @@ class CollectionPlugin(object): 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 - - if full_test_names_file_path and os.path.exists(full_test_names_file_path): - with open(full_test_names_file_path, 'r') as afile: - # in afile stored 2 dimensional array such that array[modulo_index] contains tests which should be run in this test suite - 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)) - + 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 + + if full_test_names_file_path and os.path.exists(full_test_names_file_path): + with open(full_test_names_file_path, 'r') as afile: + # in afile stored 2 dimensional array such that array[modulo_index] contains tests which should be run in this test suite + 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: module = LoadedModule.from_parent(name=test_module, parent=session) - if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): + 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) if not pytest_ignore_collect(module, session, filenames_filter, accept_filename_predicate): diff --git a/library/python/pytest/plugins/ya.make b/library/python/pytest/plugins/ya.make index c15d6f759d..e1b1e16f02 100644 --- a/library/python/pytest/plugins/ya.make +++ b/library/python/pytest/plugins/ya.make @@ -12,7 +12,7 @@ PY_SRCS( PEERDIR( library/python/filelock library/python/find_root - library/python/testing/filter + library/python/testing/filter ) IF (PYTHON2) diff --git a/library/python/pytest/plugins/ya.py b/library/python/pytest/plugins/ya.py index 1bde03042d..e396516740 100644 --- a/library/python/pytest/plugins/ya.py +++ b/library/python/pytest/plugins/ya.py @@ -29,8 +29,8 @@ import _pytest.skipping from _pytest.warning_types import PytestUnhandledCoroutineWarning -from yatest_lib import test_splitter - +from yatest_lib import test_splitter + try: import resource except ImportError: @@ -54,8 +54,8 @@ import yatest_lib.external as canon import yatest_lib.ya -from library.python.pytest import context - +from library.python.pytest import context + console_logger = logging.getLogger("console") yatest_logger = logging.getLogger("ya.test") @@ -154,7 +154,7 @@ def pytest_addoption(parser): parser.addoption("--test-list-file", action="store", dest="test_list_file") parser.addoption("--modulo", default=1, type=int) parser.addoption("--modulo-index", default=0, type=int) - parser.addoption("--partition-mode", default='SEQUENTIAL', help="Split tests according to partitoin mode") + parser.addoption("--partition-mode", default='SEQUENTIAL', help="Split tests according to partitoin mode") parser.addoption("--split-by-tests", action='store_true', help="Split test execution by tests instead of suites", default=False) parser.addoption("--project-path", action="store", default="", help="path to CMakeList where test is declared") parser.addoption("--build-type", action="store", default="", help="build type") @@ -174,7 +174,7 @@ def pytest_addoption(parser): parser.addoption("--report-deselected", action="store_true", dest="report_deselected", default=False, help="report deselected tests to the trace file") parser.addoption("--pdb-on-sigusr1", action="store_true", default=False, help="setup pdb.set_trace on SIGUSR1") parser.addoption("--test-tool-bin", help="Path to test_tool") - parser.addoption("--test-list-path", dest="test_list_path", action="store", help="path to test list", default="") + parser.addoption("--test-list-path", dest="test_list_path", action="store", help="path to test list", default="") def from_ya_test(): @@ -192,8 +192,8 @@ def pytest_configure(config): config.from_ya_test = from_ya_test() config.test_logs = collections.defaultdict(dict) config.test_metrics = {} - config.suite_metrics = {} - config.configure_timestamp = time.time() + config.suite_metrics = {} + config.configure_timestamp = time.time() context = { "project_path": config.option.project_path, "test_stderr": config.option.test_stderr, @@ -443,53 +443,53 @@ def pytest_collection_modifyitems(items, config): config.hook.pytest_deselected(items=deselected_items) items[:] = filtered_items - def filter_by_full_name(filters): - filter_set = {flt for flt in filters} - filtered_items = [] - deselected_items = [] - for item in items: - if item.nodeid in filter_set: - filtered_items.append(item) - else: - deselected_items.append(item) - - config.hook.pytest_deselected(items=deselected_items) - items[:] = filtered_items - + def filter_by_full_name(filters): + filter_set = {flt for flt in filters} + filtered_items = [] + deselected_items = [] + for item in items: + if item.nodeid in filter_set: + filtered_items.append(item) + else: + deselected_items.append(item) + + config.hook.pytest_deselected(items=deselected_items) + items[:] = filtered_items + # XXX - check to be removed when tests for peerdirs don't run for item in items: if not item.nodeid: item._nodeid = os.path.basename(item.location[0]) - if os.path.exists(config.option.test_list_path): - with open(config.option.test_list_path, 'r') as afile: - chunks = json.load(afile) - filters = chunks[config.option.modulo_index] - filter_by_full_name(filters) - else: - if config.option.test_filter: - filter_items(config.option.test_filter) - partition_mode = config.option.partition_mode - modulo = config.option.modulo - if modulo > 1: - items[:] = sorted(items, key=lambda item: item.nodeid) - modulo_index = config.option.modulo_index - split_by_tests = config.option.split_by_tests - items_by_classes = {} - res = [] - for item in items: - if item.nodeid.count("::") == 2 and not split_by_tests: - class_name = item.nodeid.rsplit("::", 1)[0] - if class_name not in items_by_classes: - items_by_classes[class_name] = [] - res.append(items_by_classes[class_name]) - items_by_classes[class_name].append(item) - else: - res.append([item]) - chunk_items = test_splitter.get_splitted_tests(res, modulo, modulo_index, partition_mode, is_sorted=True) - items[:] = [] - for item in chunk_items: - items.extend(item) - yatest_logger.info("Modulo %s tests are: %s", modulo_index, chunk_items) + if os.path.exists(config.option.test_list_path): + with open(config.option.test_list_path, 'r') as afile: + chunks = json.load(afile) + filters = chunks[config.option.modulo_index] + filter_by_full_name(filters) + else: + if config.option.test_filter: + filter_items(config.option.test_filter) + partition_mode = config.option.partition_mode + modulo = config.option.modulo + if modulo > 1: + items[:] = sorted(items, key=lambda item: item.nodeid) + modulo_index = config.option.modulo_index + split_by_tests = config.option.split_by_tests + items_by_classes = {} + res = [] + for item in items: + if item.nodeid.count("::") == 2 and not split_by_tests: + class_name = item.nodeid.rsplit("::", 1)[0] + if class_name not in items_by_classes: + items_by_classes[class_name] = [] + res.append(items_by_classes[class_name]) + items_by_classes[class_name].append(item) + else: + res.append([item]) + chunk_items = test_splitter.get_splitted_tests(res, modulo, modulo_index, partition_mode, is_sorted=True) + items[:] = [] + for item in chunk_items: + items.extend(item) + yatest_logger.info("Modulo %s tests are: %s", modulo_index, chunk_items) if config.option.mode == yatest_lib.ya.RunMode.Run: for item in items: @@ -543,7 +543,7 @@ def pytest_pyfunc_call(pyfuncitem): @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(item, call): - def logreport(report, result, call): + def logreport(report, result, call): test_item = TestItem(report, result, pytest_config.option.test_suffix) if not pytest_config.suite_metrics and context.Ctx.get("YA_PYTEST_START_TIMESTAMP"): pytest_config.suite_metrics["pytest_startup_duration"] = call.start - context.Ctx["YA_PYTEST_START_TIMESTAMP"] @@ -861,10 +861,10 @@ class TraceReportGenerator(object): self.trace('subtest-finished', message) self._test_messages[test_item.nodeid] = message - def dump_suite_metrics(self): + def dump_suite_metrics(self): message = {"metrics": pytest_config.suite_metrics} - self.trace("suite-event", message) - + self.trace("suite-event", message) + def on_error(self, test_item): self.trace('chunk_event', {"errors": [(test_item.status, self._get_comment(test_item))]}) diff --git a/library/python/pytest/ya.make b/library/python/pytest/ya.make index 060c92c313..5666a29077 100644 --- a/library/python/pytest/ya.make +++ b/library/python/pytest/ya.make @@ -10,7 +10,7 @@ PY_SRCS( main.py rewrite.py yatest_tools.py - context.py + context.py ) PEERDIR( |