Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sanitize test names created by pytest-flakefinder #201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions testmon/pytest_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,18 @@ def __init__(self, config, testmon_data):
file for file in testmon_data.stable_files if file not in failing_files
]
self.deselected_nodes = [
node for node in testmon_data.stable_nodeids if node not in failing_nodes
self.sanitize_flake_finder_name(node) for node in testmon_data.stable_nodeids if node not in failing_nodes
]

def sanitize_flake_finder_name(self, name):
# Tests generated by pytest-flakefinder end with an [N] suffix. e.g. test_foo[0],
# test_foo[12], etc. Since pytest-flakefinder is hooking to pytest the first one
# (exactly the opposite of testmon), we need consider all those tests the same one to be
# able to deselect them.
start_bracket_pos = name.rfind('[')
new_name = name if start_bracket_pos < 0 else name[0:start_bracket_pos]
return new_name

def pytest_ignore_collect(self, path, config):
strpath = os.path.relpath(path.strpath, config.rootdir.strpath)
if strpath in self.deselected_files and self.config.testmon_config[2]:
Expand All @@ -400,7 +409,7 @@ def pytest_collection_modifyitems(self, session, config, items):
selected = []
deselected = []
for item in items:
if item.nodeid in self.deselected_nodes:
if self.sanitize_flake_finder_name(item.nodeid) in self.deselected_nodes:
deselected.append(item)
else:
selected.append(item)
Expand Down