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

Fix(flaky tests): added announce function to conftest #669

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions tests/agent/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def test_agent_instana_service_name(self) -> None:
self.agent.options = StandardOptions()
assert self.agent.options.service_name == "greycake"

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_is_successful(
self,
Expand Down Expand Up @@ -104,6 +105,7 @@ def test_announce_is_successful(
assert "agentUuid" in payload
assert test_agent_uuid == payload["agentUuid"]

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_fails_with_non_200(
self,
Expand All @@ -129,6 +131,7 @@ def test_announce_fails_with_non_200(
assert "response status code" in caplog.messages[0]
assert "is NOT 200" in caplog.messages[0]

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_fails_with_non_json(
self,
Expand All @@ -153,6 +156,7 @@ def test_announce_fails_with_non_json(
assert len(caplog.records) == 1
assert "response is not JSON" in caplog.messages[0]

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_fails_with_empty_list_json(
self,
Expand All @@ -177,6 +181,7 @@ def test_announce_fails_with_empty_list_json(
assert len(caplog.records) == 1
assert "payload has no fields" in caplog.messages[0]

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_fails_with_missing_pid(
self,
Expand All @@ -202,6 +207,7 @@ def test_announce_fails_with_missing_pid(
assert len(caplog.records) == 1
assert "response payload has no pid" in caplog.messages[0]

@pytest.mark.original
@patch.object(requests.Session, "put")
def test_announce_fails_with_missing_uuid(
self,
Expand Down
11 changes: 11 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,14 @@ def announce_sensor(monkeypatch, request) -> None:
monkeypatch.setattr(TheMachine, "announce_sensor", TheMachine.announce_sensor)
else:
monkeypatch.setattr(TheMachine, "announce_sensor", always_true)


@pytest.fixture(autouse=True)
def announce(monkeypatch, request) -> None:
"""Always return `True` for `Host.announce()`"""
if "original" in request.keywords:
# If using the `@pytest.mark.original` marker before the test function,
# uses the original HostAgent.announce()
monkeypatch.setattr(HostAgent, "announce", HostAgent.announce)
else:
monkeypatch.setattr(HostAgent, "announce", always_true)
Empty file removed tests/platforms/__init__.py
Empty file.
233 changes: 0 additions & 233 deletions tests/platforms/test_host.py

This file was deleted.

Loading