Skip to content
Merged
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
10 changes: 10 additions & 0 deletions framework_tests/test_gh_issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
monkeypatched with a fake that returns canned issue states.
"""

import logging
import types
import typing as tp

Expand Down Expand Up @@ -37,6 +38,12 @@ def clean_cache(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(gh_issue.GHIssue, "issue_cache", {})


@pytest.fixture
def quiet_logger(caplog: pytest.LogCaptureFixture) -> None:
"""Silence expected error logs from the `gh_issue` module."""
caplog.set_level(logging.CRITICAL, logger=gh_issue.LOGGER.name)


def _set_github(monkeypatch: pytest.MonkeyPatch, fake: _FakeGithub | None) -> None:
"""Make `GHIssue` use the given fake GitHub instance."""
monkeypatch.setattr(gh_issue.GHIssue, "_get_github", classmethod(lambda _cls: fake))
Expand All @@ -55,6 +62,7 @@ def test_state_cached(self, monkeypatch: pytest.MonkeyPatch):
assert issue.get_state() == gh_issue.STATE_CLOSED
assert fake.calls == 1

@pytest.mark.usefixtures("quiet_logger")
def test_unknown_issue_cached(self, monkeypatch: pytest.MonkeyPatch):
"""Cache the state of a nonexistent issue, it cannot appear later."""
fake = _FakeGithub(responses=[github.UnknownObjectException(status=404)])
Expand All @@ -64,6 +72,7 @@ def test_unknown_issue_cached(self, monkeypatch: pytest.MonkeyPatch):
assert issue.get_state() == gh_issue.STATE_UNKNOWN
assert fake.calls == 1

@pytest.mark.usefixtures("quiet_logger")
def test_transient_failure_not_cached(self, monkeypatch: pytest.MonkeyPatch):
"""Don't cache a failed state retrieval, the next call may succeed."""
fake = _FakeGithub(responses=[RuntimeError("API is down"), "OPEN"])
Expand All @@ -74,6 +83,7 @@ def test_transient_failure_not_cached(self, monkeypatch: pytest.MonkeyPatch):
assert issue.get_state() == "open"
assert fake.calls == 2

@pytest.mark.usefixtures("quiet_logger")
def test_no_github_instance(self, monkeypatch: pytest.MonkeyPatch):
"""Report a state retrieval failure when the GitHub instance is not available."""
_set_github(monkeypatch, None)
Expand Down
Loading