MCPcopy
hub / github.com/saltstack/salt / groups_collection_modifyitems

Function groups_collection_modifyitems

tests/conftest.py:906–947  ·  view source on GitHub ↗
(config, items)

Source from the content-addressed store, hash-verified

904
905# ----- Test Groups Selection --------------------------------------------------------------------------------------->
906def groups_collection_modifyitems(config, items):
907 group_count = config.getoption("test-group-count")
908 group_id = config.getoption("test-group")
909
910 if not group_count or not group_id:
911 # We're not selection tests using groups, don't do any filtering
912 return
913
914 if group_count == 1:
915 # Just one group, don't do any filtering
916 return
917
918 terminal_reporter = config.pluginmanager.get_plugin("terminalreporter")
919
920 if config.getoption("--last-failed") or config.getoption("--failed-first"):
921 # This is a test failure rerun, applying test groups would break this
922 terminal_reporter.write(
923 "\nNot splitting collected tests into chunks since --lf/--last-failed or "
924 "-ff/--failed-first was passed on the CLI.\n",
925 yellow=True,
926 )
927 return
928
929 total_items = len(items)
930
931 # Devide into test groups
932 test_groups = more_itertools.divide(group_count, items)
933 # Pick the right group
934 tests_in_group = list(test_groups.pop(group_id - 1))
935 # The rest are deselected tests
936 deselected = list(more_itertools.collapse(test_groups))
937 # Sanity check
938 assert len(tests_in_group) + len(deselected) == total_items
939 # Replace all items in the list
940 items[:] = tests_in_group
941 if deselected:
942 config.hook.pytest_deselected(items=deselected)
943
944 terminal_reporter.write(
945 f"Running test group #{group_id}(out of #{group_count}) ({len(items)} out of {total_items} tests)\n",
946 yellow=True,
947 )
948
949
950# <---- Test Groups Selection ----------------------------------------------------------------------------------------

Callers 1

Calls 3

listFunction · 0.50
writeMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected