Skip to content
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
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ pythonpath = src
testpaths =
tests
tests_aws
markers =
original: mark test to use the original method instead of the mocked ones under `conftest.py`
2 changes: 1 addition & 1 deletion tests/agent/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def test_get_from_structure():
agent.announce_data = AnnounceData(pid=1234, agentUuid="value")
assert agent.get_from_structure() == {"e": 1234, "h": "value"}


@pytest.mark.original
Comment thread
GSVarsha marked this conversation as resolved.
def test_is_agent_listening(
caplog: LogCaptureFixture,
):
Expand Down
13 changes: 12 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def context(span: InstanaSpan) -> Context:
return set_span_in_context(span)


def always_true(_: object) -> bool:
def always_true(_: object, *args: object, **kwargs: object) -> bool:
return True


Expand Down Expand Up @@ -185,3 +185,14 @@ def prepare_and_report_data(monkeypatch, request):
)
else:
monkeypatch.setattr(BaseCollector, "prepare_and_report_data", always_true)

# Mocking HostAgent.is_agent_listening()
@pytest.fixture(autouse=True)
def is_agent_listening(monkeypatch, request) -> None:
"""Always return `True` for `HostAgent.is_agent_listening()`"""
if "original" in request.keywords:
# If using the `@pytest.mark.original` marker before the test function,
# uses the original HostAgent.is_agent_listening()
monkeypatch.setattr(HostAgent, "is_agent_listening", HostAgent.is_agent_listening)
else:
monkeypatch.setattr(HostAgent, "is_agent_listening", always_true)
5 changes: 3 additions & 2 deletions tests/platforms/test_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import logging
import unittest
import pytest

from mock import MagicMock, patch
import requests
Expand Down Expand Up @@ -230,7 +231,7 @@ def test_announce_fails_with_missing_uuid(self, mock_requests_session_put):
self.assertEqual(len(log.records), 1)
self.assertIn('response payload has no agentUuid', log.output[0])


@pytest.mark.original
@patch.object(requests.Session, "get")
def test_agent_connection_attempt(self, mock_requests_session_get):
mock_response = MagicMock()
Expand All @@ -248,7 +249,7 @@ def test_agent_connection_attempt(self, mock_requests_session_get):
self.assertTrue(result)
self.assertIn(msg, log.output[0])


@pytest.mark.original
@patch.object(requests.Session, "get")
def test_agent_connection_attempt_fails_with_404(self, mock_requests_session_get):
mock_response = MagicMock()
Expand Down