Skip to content

Migrate config assertion tests away from requests#22722

Merged
mwdd146980 merged 33 commits intomwdd146980/httpx-migration-basefrom
mwdd146980/phase1b-step2-config-assertions
Mar 19, 2026
Merged

Migrate config assertion tests away from requests#22722
mwdd146980 merged 33 commits intomwdd146980/httpx-migration-basefrom
mwdd146980/phase1b-step2-config-assertions

Conversation

@mwdd146980
Copy link
Contributor

@mwdd146980 mwdd146980 commented Feb 25, 2026

What does this PR do?

Test Decoupling Step 2 (plan). Stacked on #22676.

Motivation

Many integration tests patch requests.Session and use assert_called_with just to verify config propagation. This couples tests to the HTTP transport library and requires running the full check with a mock response even though the values under test are available on check.http.options at construction time.

Approach

  • Config tests now assert on check.http.options directly — no HTTP call, no session mock, no mock.ANY boilerplate. The gap between options and actual session kwargs is already covered by test_api.py in the base package.
  • Functional tests that need HTTP responses use the mock_http fixture from Step 1 instead of patching requests.Session.
  • Added get_header()/set_header() to RequestsWrapper and HTTPClientProtocol so tests and production code (vault) don't reach into options['headers'] directly.

Verification

All 19 affected integrations pass their test suites. Detailed design notes: Confluence.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Copy link
Contributor Author

mwdd146980 commented Feb 25, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@mwdd146980 mwdd146980 changed the title Migrate couch config assertion test to check.http.options Migrate config assertion tests from requests.Session patches to check.http.options Feb 25, 2026
@mwdd146980 mwdd146980 changed the title Migrate config assertion tests from requests.Session patches to check.http.options Migrate config assertion tests to library-agnostic patterns Feb 25, 2026
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 96.80851% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 89.34%. Comparing base (3bc6e95) to head (e51c89a).
⚠️ Report is 1 commits behind head on mwdd146980/httpx-migration-base.

Additional details and impacted files
Flag Coverage Δ
active_directory ?
activemq_xml ?
aerospike ?
airflow ?
amazon_msk ?
ambari ?
apache ?
appgate_sdp ?
arangodb ?
argo_rollouts ?
argo_workflows ?
argocd ?
aspdotnet ?
avi_vantage ?
aws_neuron ?
azure_iot_edge ?
boundary ?
btrfs ?
cacti ?
calico ?
cassandra_nodetool ?
celery ?
ceph ?
cert_manager ?
cilium ?
cisco_aci ?
citrix_hypervisor ?
clickhouse ?
cloud_foundry_api ?
cloudera ?
cockroachdb ?
consul ?
coredns ?
couch ?
couchbase ?
crio ?
datadog_checks_base ?
datadog_checks_dev ?
datadog_checks_downloader ?
datadog_cluster_agent ?
dcgm ?
ddev ?
directory ?
disk ?
dns_check ?
dotnetclr ?
druid ?
duckdb ?
ecs_fargate ?
eks_fargate ?
elastic ?
envoy ?
esxi ?
etcd ?
exchange_server ?
external_dns ?
falco ?
fluentd ?
fluxcd ?
fly_io ?
foundationdb ?
gearmand ?
gitlab ?
gitlab_runner ?
glusterfs ?
go_expvar ?
gunicorn ?
haproxy ?
harbor ?
hazelcast ?
hdfs_datanode ?
hdfs_namenode ?
http_check ?
ibm_ace ?
ibm_db2 ?
ibm_i ?
ibm_mq ?
ibm_was ?
iis ?
impala ?
infiniband ?
istio ?
kafka_consumer ?
karpenter ?
keda ?
kong ?
krakend ?
kube_apiserver_metrics ?
kube_controller_manager ?
kube_dns ?
kube_metrics_server ?
kube_proxy ?
kube_scheduler ?
kubeflow ?
kubelet ?
kubernetes_cluster_autoscaler ?
kubernetes_state ?
kubevirt_api ?
kubevirt_controller ?
kubevirt_handler ?
kuma ?
kyototycoon ?
kyverno ?
lighttpd ?
linkerd ?
linux_proc_extras ?
litellm ?
lustre ?
mac_audit_logs ?
mapr ?
mapreduce ?
marathon ?
marklogic ?
mcache ?
mesos_master ?
milvus ?
mongo ?
mysql ?
nagios ?
network ?
nfsstat ?
nginx ?
nginx_ingress_controller ?
nvidia_nim ?
nvidia_triton ?
octopus_deploy ?
openldap ?
openmetrics ?
openstack ?
openstack_controller ?
pdh_check ?
pgbouncer ?
php_fpm ?
postfix ?
postgres ?
powerdns_recursor ?
process ?
prometheus ?
proxmox ?
proxysql ?
pulsar ?
quarkus ?
rabbitmq ?
ray ?
redisdb ?
rethinkdb ?
riak ?
riakcs ?
sap_hana ?
scylla ?
silk ?
silverstripe_cms ?
singlestore ?
slurm ?
snmp ?
snowflake ?
sonarqube ?
sonatype_nexus ?
spark ?
sqlserver ?
squid ?
ssh_check ?
statsd ?
strimzi ?
supabase ?
supervisord ?
system_core ?
system_swap ?
tcp_check ?
teamcity ?
tekton ?
teleport ?
temporal ?
teradata ?
tibco_ems ?
tls ?
torchserve ?
traefik_mesh ?
traffic_server ?
twemproxy ?
twistlock ?
varnish ?
vault ?
velero ?
vertica ?
vllm ?
voltdb ?
vsphere ?
weaviate ?
win32_event_log ?
windows_performance_counters ?
windows_service ?
wmi_check ?
yarn ?
zk ?

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

mwdd146980 and others added 30 commits March 19, 2026 15:08
Replace mock.patch('...requests.Session') + assert_called_with pattern
with the new http_client_session fixture. The full _request() option-merging
flow now runs, and the assertion verifies the timeout kwarg forwarded to
session.get().

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace mock.patch('...requests.Session') + assert_called_with pattern
with the new http_client_session fixture. Also replace third-party mock
import with unittest.mock throughout the file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace mock.patch('...requests.Session') with the http_client_session
fixture in test__get_data (error-handling) and test_config (config
assertion).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace mock.patch('...requests.Session') patterns with the
http_client_session fixture in test_consul_request (error-handling)
and test_config (config assertion).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extend _CanonicalMock with call_count, call_args, and call_args_list
properties to support tests that introspect individual calls beyond
assert_called_with. Then migrate test_get_models to use the fixture
instead of patching requests.Session directly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…lient_session

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… and mock_http

- Remove http_client_session fixture, _CanonicalMock, and supporting code from
  http_testing.py; update __all__ to ['MockHTTPResponse', 'mock_http']
- Config tests (couch, gitlab_runner, marathon, rabbitmq, consul, etcd,
  ecs_fargate): drop http_client_session + check.check() + URL assertion;
  assert check.http.options[key] == value directly — no HTTP call needed
- Functional tests (rabbitmq test__get_data, consul test_consul_request,
  mesos_master test_can_connect_service_check, torchserve test_get_models):
  replace http_client_session with mock_http
- mesos_master: set mock_http.options = {'verify': True} before check
  instantiation since MesosMaster.__init__ reads self.http.options['verify']

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
create_autospec does not expose Protocol class-variable annotations at
runtime, so mock_http now explicitly sets client.options = MagicMock(spec=dict).
This provides a proper dict-like mock for any check that reads http.options
in __init__ (mesos_slave, mesos_master), removing the per-test workaround
of assigning mock_http.options = {'verify': True} before instantiation.

With options always present on the mock, the hasattr guard in
base_scraper.py is also removed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… etcd config test

- Move timedelta and HTTPStatusError to top-level imports in http_testing.py
- Complete HTTPResponseProtocol: add status_code, content, text, headers,
  json(), raise_for_status(), close() — previously the protocol only declared
  streaming methods and had no practical type safety
- Remove inaccurate comment from test_authtoken.py (claimed MockHTTPResponse
  was a "drop-in replacement" and "httpx compatible")
- Move etcd test_config out of test_integration.py into a new test_unit.py
  so it no longer requires a docker environment to run
- Add mock_http fixture test (verifies PropertyMock patch reaches check.http)
- Add MockHTTPResponse tests: iter_content chunking, iter_lines decode_unicode
  and custom delimiter, file_path constructor, raise_for_status 2xx no-op

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…fixture

mock_http was moved to datadog_checks_dev/plugin/pytest.py in PR #22710 and is
auto-available to all tests via the plugin. Remove the duplicate definition from
http_testing.py and drop the now-unnecessary noqa: F401 conftest imports.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Protocol annotation-only attributes (options: dict[str, Any]) are not
included in dir() and thus not auto-mocked by create_autospec. Checks
like mesos_master that access self.http.options in __init__ raised
AttributeError when using the mock_http fixture.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add get_header(name, default) and set_header(name, value) methods to
  RequestsWrapper and HTTPClientProtocol, replacing direct access to
  http.options['headers'][key]
- Add TestGetHeader and TestSetHeader unit tests in test_headers.py
- Migrate consul, php_fpm config tests to use get_header()
- Migrate openmetrics tests to use get_header()
- Migrate vault production code to use set_header()

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
MagicMock does not preserve dict item assignment, so any check that
writes to self.http.options in __init__ would silently discard the
mutation when tested with mock_http. Use a real dict with the standard
RequestsWrapper keys so item assignment and retrieval work correctly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Vault legacy _set_header now delegates to http_wrapper.set_header()
  instead of direct dict mutation
- mock_http fixture get_header/set_header now have side_effects that
  read/write client.options['headers'], matching real RequestsWrapper

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove trivial tests that duplicate stdlib behavior or are implicitly
covered by other tests. Consolidate where possible (7→3 header tests,
14→8 http_testing tests).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…st_http_testing.py

Match the dominant repo convention of top-level test functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both requests and httpx treat headers case-insensitively, so the API
should too. Case folding happens inside the methods; options['headers']
remains a plain dict. set_header preserves the original key casing when
overwriting an existing entry.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address steveny91's nit: the `assert isinstance(e, RabbitMQException)`
lines inside `pytest.raises` blocks are dead code — execution leaves the
with block when the exception is raised, so the assert never runs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment