Created
August 20, 2024 20:48
-
-
Save leshikus/2e5dc8b31bc3d6e9972535630e14ec10 to your computer and use it in GitHub Desktop.
a snipped from pytest_select plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pytest_collection_modifyitems(session, config, items): | |
seen_test_names = set() | |
for item in items: | |
seen_test_names.add(item.name) | |
seen_test_names.add(item.nodeid) | |
selection_file_name = config.getoption("deselectfromfile") | |
if selection_file_name is not None: | |
selection_file_path = Path(selection_file_name) | |
with selection_file_path.open("rt", encoding="UTF-8") as selection_file: | |
test_names = {test_name.strip() for test_name in selection_file} | |
missing_test_names = test_names - seen_test_names | |
if missing_test_names: | |
# If any items remain in `test_names` those tests either don't exist or | |
# have been deselected by another way - warn user | |
message = ( | |
f"pytest-select: Missing deselected test names:\n - " | |
) | |
message += "\n - ".join(missing_test_names) | |
if config.getoption("selectfailonmissing"): | |
raise UsageError(message) | |
warnings.warn(message, PytestSelectWarning) | |
for item in items: | |
if item.name in test_names or item.nodeid in test_names: | |
item.add_marker(skip) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment