Skip to content

Commit debc3b4

Browse files
authored
refactor: Remove is_processed flag from test metrics (#335)
The goal of this change is to simplify the process and simply use the deadline to know if a test has already been processed. If a deadline is set for the given test, it means it has been processed. Depends-On: #334
1 parent 905d890 commit debc3b4

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

pytest_mergify/flaky_detection.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ def initial_duration(self) -> datetime.timedelta:
5959
+ self.initial_teardown_duration
6060
)
6161

62-
# NOTE(remyduthu): We need this flag because we may have processed a test
63-
# without scheduling reruns for it (e.g., because it was too slow).
64-
is_processed: bool = dataclasses.field(default=False)
65-
6662
rerun_count: int = dataclasses.field(default=0)
6763
"Represents the number of times the test has been rerun so far."
6864

@@ -309,7 +305,6 @@ def set_test_deadline(
309305
metrics.deadline = datetime.datetime.now(datetime.timezone.utc) + (
310306
self._get_remaining_budget_duration() / self._count_remaining_tests()
311307
)
312-
metrics.is_processed = True
313308

314309
if not timeout:
315310
return
@@ -359,7 +354,7 @@ def _count_remaining_tests(self) -> int:
359354
tests = self._context.unhealthy_test_names
360355

361356
already_processed_tests = {
362-
test for test, metrics in self._test_metrics.items() if metrics.is_processed
357+
test for test, metrics in self._test_metrics.items() if metrics.deadline
363358
}
364359

365360
return max(len(tests) - len(already_processed_tests), 1)

tests/test_flaky_detection.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,9 @@ def test_flaky_detector_count_remaining_tests() -> None:
106106
existing_test_names=["foo", "bar", "baz"]
107107
)
108108
detector._test_metrics = {
109-
"foo": flaky_detection._TestMetrics(is_processed=True),
109+
"foo": flaky_detection._TestMetrics(
110+
deadline=datetime.datetime.now(datetime.timezone.utc)
111+
),
110112
"bar": flaky_detection._TestMetrics(),
111113
"baz": flaky_detection._TestMetrics(),
112114
}

0 commit comments

Comments
 (0)