Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
198fb22
Update dependency resolution
Apr 28, 2026
c165023
Migrate temporal, fluxcd, dcgm, impala conftest.py to mock_http
mwdd146980 Apr 10, 2026
a4bfd7f
Migrate nutanix conftest.py to mock_http
mwdd146980 Apr 10, 2026
c3c25fc
Migrate yarn mocked_bad_cert_request to config assertion
mwdd146980 Apr 14, 2026
98ef8da
Fix OM v1 mixin to use self.http + migrate 8 conftest.py files
mwdd146980 Apr 18, 2026
16b3870
Revert mixin change, patch get_http_handler in conftest fixtures instead
mwdd146980 Apr 18, 2026
541e1b3
Extract shared mock_openmetrics_http/mock_prometheus_http fixtures
mwdd146980 Apr 18, 2026
a2144b4
Address review findings: nutanix retry tests, changelog, gitlab nit
mwdd146980 Apr 21, 2026
3d20145
Fix nutanix conftest: restore mocker fixture + comments stripped duri…
mwdd146980 Apr 28, 2026
2bcdf03
Set ignore_tls_warning on mock_prometheus_http to handle future https…
mwdd146980 Apr 28, 2026
44a17da
Document mock_openmetrics_http dual interception (v1 patch + v2 Prope…
mwdd146980 Apr 28, 2026
9848e61
Use MockHTTPResponse(status_code=404) for nutanix conftest fall-through
mwdd146980 Apr 28, 2026
573ae6c
Rename yarn test_ssl_verification to test_tls_verify_config_propagates
mwdd146980 Apr 28, 2026
3e1069a
Restore yarn SSL catch-translate coverage via mock_http.get.side_effect
mwdd146980 May 1, 2026
c5b71ca
Minimize test_ssl_verification diff vs pre-migration shape
mwdd146980 May 1, 2026
8a139cc
Restore original comments in test_ssl_verification
mwdd146980 May 1, 2026
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
24 changes: 7 additions & 17 deletions cilium/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import os

import mock
import pytest

from datadog_checks.base.utils.common import get_docker_hostname
from datadog_checks.base.utils.http_testing import MockHTTPResponse
from datadog_checks.cilium import CiliumCheck
from datadog_checks.dev import run_command
from datadog_checks.dev.kind import kind_run
Expand Down Expand Up @@ -198,28 +198,18 @@ def operator_instance_use_openmetrics():


@pytest.fixture()
def mock_agent_data():
def mock_agent_data(mock_openmetrics_http):
f_name = os.path.join(os.path.dirname(__file__), "fixtures", "agent_metrics.txt")
with open(f_name, "r") as f:
text_data = f.read()
with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split("\n"), headers={"Content-Type": "text/plain"}
),
):
yield
mock_openmetrics_http.get.return_value = MockHTTPResponse(content=text_data, headers={"Content-Type": "text/plain"})
yield


@pytest.fixture()
def mock_operator_data():
def mock_operator_data(mock_openmetrics_http):
f_name = os.path.join(os.path.dirname(__file__), "fixtures", "operator_metrics.txt")
with open(f_name, "r") as f:
text_data = f.read()
with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split("\n"), headers={"Content-Type": "text/plain"}
),
):
yield
mock_openmetrics_http.get.return_value = MockHTTPResponse(content=text_data, headers={"Content-Type": "text/plain"})
yield
2 changes: 1 addition & 1 deletion datadog_checks_dev/changelog.d/22676.added
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add mock_http fixture for library-agnostic HTTP client mocking in integration tests.
Add mock_http, mock_openmetrics_http, and mock_prometheus_http fixtures for library-agnostic HTTP client mocking in integration tests.
26 changes: 26 additions & 0 deletions datadog_checks_dev/datadog_checks/dev/plugin/pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,32 @@ def _set_header(name, value):
return client


@pytest.fixture
def mock_openmetrics_http(mock_http, mocker):
"""OpenMetrics HTTP mock with dual interception:

- v1 checks (OpenMetricsBaseCheck): patches OpenMetricsScraperMixin.get_http_handler to return mock_http.
- v2 checks (OpenMetricsBaseCheckV2): inherited via mock_http's AgentCheck.http PropertyMock; the
get_http_handler patch is unused on this path because v2 calls self.http.get(...) directly.
"""
mocker.patch(
'datadog_checks.base.checks.openmetrics.mixins.OpenMetricsScraperMixin.get_http_handler',
return_value=mock_http,
)
return mock_http


@pytest.fixture
def mock_prometheus_http(mock_http, mocker):
"""mock_http with PrometheusScraperMixin.get_http_handler patched to return it."""
mock_http.ignore_tls_warning = False
mocker.patch(
'datadog_checks.base.checks.prometheus.mixins.PrometheusScraperMixin.get_http_handler',
return_value=mock_http,
)
return mock_http


@pytest.fixture
def mock_http_response_per_endpoint(mocker, mock_response):
@overload
Expand Down
14 changes: 5 additions & 9 deletions datadog_cluster_agent/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
import os
from copy import deepcopy

import mock
import pytest

from datadog_checks.base.utils.http_testing import MockHTTPResponse

INSTANCE = {'prometheus_url': 'http://localhost:5000/metrics'}


Expand All @@ -21,14 +22,9 @@ def instance():


@pytest.fixture()
def mock_metrics_endpoint():
def mock_metrics_endpoint(mock_openmetrics_http):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'metrics.txt')
with open(f_name, 'r') as f:
text_data = f.read()
with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split("\n"), headers={'Content-Type': "text/plain"}
),
):
yield
mock_openmetrics_http.get.return_value = MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
yield
24 changes: 7 additions & 17 deletions dcgm/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

import copy
import os
from unittest import mock

import pytest

from datadog_checks.base.utils.http_testing import MockHTTPResponse
from datadog_checks.dcgm import DcgmCheck
from datadog_checks.dev import docker_run
from datadog_checks.dev.conditions import CheckDockerLogs, CheckEndpoints
Expand Down Expand Up @@ -40,28 +40,18 @@ def check(instance):


@pytest.fixture()
def mock_metrics():
def mock_metrics(mock_http):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'metrics.txt')
with open(f_name, 'r') as f:
text_data = f.read()
with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split("\n"), headers={'Content-Type': "text/plain"}
),
):
yield
mock_http.get.return_value = MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
yield


@pytest.fixture()
def mock_label_remap():
def mock_label_remap(mock_http):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'label_remap.txt')
with open(f_name, 'r') as f:
text_data = f.read()
with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split("\n"), headers={'Content-Type': "text/plain"}
),
):
yield
mock_http.get.return_value = MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
yield
14 changes: 5 additions & 9 deletions external_dns/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,23 @@
import os
from copy import deepcopy

import mock
import pytest

from datadog_checks.base.utils.http_testing import MockHTTPResponse

from .common import FIXTURE_DIR

INSTANCE = {'prometheus_url': 'http://localhost:7979/metrics', 'tags': ['custom:tag']}


@pytest.fixture
def mock_external_dns():
def mock_external_dns(mock_openmetrics_http):
f_name = os.path.join(FIXTURE_DIR, 'metrics.txt')
with open(f_name, 'r') as f:
text_data = f.read()

with mock.patch(
'requests.Session.get',
return_value=mock.MagicMock(
status_code=200, iter_lines=lambda **kwargs: text_data.split('\n'), headers={'Content-Type': 'text/plain'}
),
):
yield
mock_openmetrics_http.get.return_value = MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
yield


@pytest.fixture(scope='session')
Expand Down
28 changes: 7 additions & 21 deletions fluxcd/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
# Licensed under a 3-clause BSD style license (see LICENSE)
import os
from contextlib import ExitStack
from unittest import mock

import pytest

from datadog_checks.base.utils.http_testing import MockHTTPResponse
from datadog_checks.dev import get_here
from datadog_checks.dev.kind import kind_run
from datadog_checks.dev.kube_port_forward import port_forward
Expand Down Expand Up @@ -69,36 +69,22 @@ def check(instance):


@pytest.fixture()
def mock_metrics_v1():
def mock_metrics_v1(mock_http):
fixture_file = os.path.join(os.path.dirname(__file__), "fixtures", "metrics-v1.txt")

with open(fixture_file, "r") as f:
content = f.read()

with mock.patch(
"requests.Session.get",
return_value=mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: content.split("\n"),
headers={"Content-Type": "text/plain"},
),
):
yield
mock_http.get.return_value = MockHTTPResponse(content=content, headers={"Content-Type": "text/plain"})
yield


@pytest.fixture()
def mock_metrics_v2():
def mock_metrics_v2(mock_http):
fixture_file = os.path.join(os.path.dirname(__file__), "fixtures", "metrics-v2.txt")

with open(fixture_file, "r") as f:
content = f.read()

with mock.patch(
"requests.Session.get",
return_value=mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: content.split("\n"),
headers={"Content-Type": "text/plain"},
),
):
yield
mock_http.get.return_value = MockHTTPResponse(content=content, headers={"Content-Type": "text/plain"})
yield
37 changes: 9 additions & 28 deletions gitlab/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from contextlib import contextmanager
from time import sleep

import mock
import pytest
import requests

from datadog_checks.base.utils.http_testing import MockHTTPResponse
from datadog_checks.dev import EnvVars, TempDir, docker_run
from datadog_checks.dev._env import get_state, save_state
from datadog_checks.dev.conditions import CheckEndpoints
Expand Down Expand Up @@ -102,12 +102,9 @@ def dd_environment():


@pytest.fixture()
def mock_data():
with mock.patch(
'requests.Session.get',
side_effect=mocked_requests_get,
):
yield
def mock_data(mock_openmetrics_http):
mock_openmetrics_http.get.side_effect = mocked_requests_get
yield


def mocked_requests_get(*args, **kwargs):
Expand All @@ -117,45 +114,29 @@ def mocked_requests_get(*args, **kwargs):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'readiness_check.json')
with open(f_name, 'r') as f:
text_data = f.read()
response = mock.MagicMock()
response.status_code = 200
response.json.return_value = json.loads(text_data)
return response
return MockHTTPResponse(json_data=json.loads(text_data))

elif url == "http://{}:{}/-/liveness".format(HOST, GITLAB_LOCAL_PORT) or url == "http://{}:{}/-/health".format(
HOST, GITLAB_LOCAL_PORT
):
response = mock.MagicMock()
response.status_code = 200
return response
return MockHTTPResponse()
elif url == "http://{}:{}/-/metrics".format(HOST, GITLAB_LOCAL_PORT):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'metrics.txt')

with open(f_name, 'r') as f:
text_data = f.read()
return mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: text_data.split("\n"),
headers={'Content-Type': "text/plain"},
)
return MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
elif url == "http://{}:{}/metrics".format(HOST, GITLAB_LOCAL_GITALY_PROMETHEUS_PORT):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'gitaly.txt')

with open(f_name, 'r') as f:
text_data = f.read()
return mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: text_data.split("\n"),
headers={'Content-Type': "text/plain"},
)
return MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
elif url == "http://{}:{}/api/v4/version".format(HOST, GITLAB_LOCAL_PORT):
f_name = os.path.join(os.path.dirname(__file__), 'fixtures', 'version.json')
with open(f_name, 'r') as f:
text_data = f.read()
response = mock.MagicMock()
response.status_code = 200
response.json.return_value = json.loads(text_data)
return response
return MockHTTPResponse(json_data=json.loads(text_data))

pytest.fail("url `{}` not registered".format(args[0]))

Expand Down
21 changes: 7 additions & 14 deletions gitlab_runner/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import os

import mock
import pytest

from datadog_checks.base.utils.http_testing import MockHTTPResponse
from datadog_checks.dev import docker_run
from datadog_checks.dev.conditions import CheckDockerLogs, CheckEndpoints

Expand Down Expand Up @@ -68,21 +68,14 @@ def _mocked_requests_get(*args, **kwargs):
fixtures_path = os.path.join(os.path.dirname(__file__), 'fixtures', 'metrics.txt')
with open(fixtures_path, 'r') as f:
text_data = f.read()
return mock.MagicMock(
status_code=200,
iter_lines=lambda **kwargs: text_data.split("\n"),
headers={'Content-Type': "text/plain"},
)
return MockHTTPResponse(content=text_data, headers={'Content-Type': 'text/plain'})
elif url == 'http://{}:{}/ci'.format(HOST, GITLAB_LOCAL_MASTER_PORT):
return mock.MagicMock(status_code=200)
return MockHTTPResponse()

return mock.MagicMock(status_code=404)
return MockHTTPResponse(status_code=404)


@pytest.fixture()
def mock_data():
with mock.patch(
'requests.Session.get',
side_effect=_mocked_requests_get,
):
yield
def mock_data(mock_openmetrics_http):
mock_openmetrics_http.get.side_effect = _mocked_requests_get
yield
Loading
Loading