Skip to content

Commit b195956

Browse files
authored
fix(ci-insights): Disable flaky detection without existing tests (#239)
Fixes: MRGFY-5913
1 parent f5ed58e commit b195956

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pytest_mergify/flaky_detection.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,13 @@ def _fetch_existing_tests(self) -> typing.List[str]:
6565

6666
response.raise_for_status()
6767

68-
return typing.cast(typing.List[str], response.json()["test_names"])
68+
result = typing.cast(typing.List[str], response.json()["test_names"])
69+
if len(result) == 0:
70+
raise RuntimeError(
71+
f"No existing tests found for '{self.full_repository_name}' repository on branch '{self.branch_name}'",
72+
)
73+
74+
return result
6975

7076
def detect_from_report(self, report: _pytest.reports.TestReport) -> bool:
7177
if report.when != "call":

tests/test_ci_insights.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ def test_load_flaky_detection_error(monkeypatch: pytest.MonkeyPatch) -> None:
7272
assert "500 Server Error" in client.flaky_detector_error_message
7373

7474

75+
@responses.activate
76+
def test_load_flaky_detection_error_without_existing_tests(
77+
monkeypatch: pytest.MonkeyPatch,
78+
) -> None:
79+
_set_test_environment(monkeypatch)
80+
81+
_make_quarantine_mock()
82+
_make_test_names_mock([])
83+
84+
client = _make_test_client()
85+
assert client.flaky_detector is None
86+
assert client.flaky_detector_error_message is not None
87+
assert (
88+
"No existing tests found for 'Mergifyio/pytest-mergify' repository on branch 'main'"
89+
in client.flaky_detector_error_message
90+
)
91+
92+
7593
@responses.activate
7694
def test_flaky_detection(
7795
monkeypatch: pytest.MonkeyPatch,

0 commit comments

Comments
 (0)