MCPcopy Create free account
hub / github.com/catboost/catboost / pytest_collection_modifyitems

Function pytest_collection_modifyitems

library/python/pytest/plugins/ya.py:461–565  ·  view source on GitHub ↗
(items, config)

Source from the content-addressed store, hash-verified

459
460@pytest.hookimpl(trylast=True)
461def pytest_collection_modifyitems(items, config):
462
463 def filter_items(filters):
464 filtered_items = []
465 deselected_items = []
466 for item in items:
467 canonical_node_id = str(CustomTestItem(item.nodeid, item.location[0], pytest_config.option.test_suffix))
468 matched = False
469 for flt in filters:
470 if "::" not in flt and "*" not in flt:
471 flt += "*" # add support for filtering by module name
472 if canonical_node_id.endswith(flt) or fnmatch.fnmatch(tools.escape_for_fnmatch(canonical_node_id), tools.escape_for_fnmatch(flt)):
473 matched = True
474 if matched:
475 filtered_items.append(item)
476 else:
477 deselected_items.append(item)
478
479 config.hook.pytest_deselected(items=deselected_items)
480 items[:] = filtered_items
481
482 def filter_by_full_name(filters):
483 filter_set = {flt for flt in filters}
484 filtered_items = []
485 deselected_items = []
486 for item in items:
487 if item.nodeid in filter_set:
488 filtered_items.append(item)
489 else:
490 deselected_items.append(item)
491
492 config.hook.pytest_deselected(items=deselected_items)
493 items[:] = filtered_items
494
495 # XXX - check to be removed when tests for peerdirs don't run
496 for item in items:
497 if not item.nodeid:
498 item._nodeid = os.path.basename(item.location[0])
499 if os.path.exists(config.option.test_list_path):
500 with open(config.option.test_list_path, 'r') as afile:
501 chunks = json.load(afile)
502 filters = chunks[config.option.modulo_index]
503 filter_by_full_name(filters)
504 else:
505 test_filter = get_test_filter(config.option)
506 if test_filter:
507 filter_items(test_filter)
508
509 partition_mode = config.option.partition_mode
510 modulo = config.option.modulo
511 if modulo > 1:
512 items[:] = sorted(items, key=lambda item: item.nodeid)
513 modulo_index = config.option.modulo_index
514 split_by_tests = config.option.split_by_tests
515 items_by_classes = {}
516 res = []
517 for item in items:
518 if item.nodeid.count("::") == 2 and not split_by_tests:

Callers

nothing calls this directly

Calls 15

filter_by_full_nameFunction · 0.85
get_test_filterFunction · 0.85
filter_itemsFunction · 0.85
NotLaunchedTestItemClass · 0.85
CustomTestItemClass · 0.85
hasattrFunction · 0.85
_get_item_tagsFunction · 0.85
on_start_test_classMethod · 0.80
on_finish_test_caseMethod · 0.80
on_finish_test_classMethod · 0.80
openFunction · 0.50
loadMethod · 0.45

Tested by

no test coverage detected