Skip to content

fix: CI test suite is very WET#1757

Closed
bluetoothbot wants to merge 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/fix-issue-1738
Closed

fix: CI test suite is very WET#1757
bluetoothbot wants to merge 1 commit into
python-zeroconf:masterfrom
bluetoothbot:koan/fix-issue-1738

Conversation

@bluetoothbot

@bluetoothbot bluetoothbot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Added mock_incoming_msg() helper to build DNSIncoming response messages from record lists
  • Added zc_loopback pytest fixture for loopback-only Zeroconf instances with automatic cleanup
  • Added aiozc_loopback pytest fixture for loopback-only AsyncZeroconf instances with automatic cleanup
  • Eliminates repeated manual setup/teardown boilerplate across test suite

Why

Tests repeatedly create loopback-only Zeroconf instances with identical setup and teardown patterns. Extracting these into reusable fixtures and a message helper reduces duplication and makes test code more consistent and maintainable.

How

  • Created mock_incoming_msg() in tests/__init__.py that constructs a DNSIncoming from a list of DNSRecords using DNSOutgoing wire encoding
  • Added zc_loopback fixture in conftest.py yielding a loopback Zeroconf(interfaces=["127.0.0.1"]) with automatic cleanup via try/finally
  • Added aiozc_loopback fixture in conftest.py yielding a loopback AsyncZeroconf with automatic async cleanup
  • Fixtures are idempotent — tests can safely call .close() or async_close() directly without risk of errors

Testing

  • Fixtures follow pytest conventions with proper setup/teardown guarantees
  • Helper function encapsulates wire encoding pattern for response injection
  • No new test cases required — these are infrastructure utilities for existing and future tests

Limitations & Risk

  • Fixtures are hardcoded to loopback-only (127.0.0.1); tests requiring multi-interface behavior should not use them
  • Complex multi-record message construction may still require manual DNSIncoming assembly beyond what the helper provides

Fixes #1738


Generated by Koan /fix


Quality Report

Changes: 2 files changed, 43 insertions(+), 3 deletions(-)

Code scan: clean

Tests: passed (4 PASSED)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

… helper

The loopback `Zeroconf(interfaces=["127.0.0.1"])` instantiation pattern
is duplicated 160+ times across the test suite, with inconsistent close
handling. The `AsyncZeroconf` form repeats another 70+ times. The
`mock_incoming_msg` factory that wraps DNS records into a `DNSIncoming`
response is defined inline in test_browser.py and three places in
test_info.py.

Add shared fixtures and a helper that follow-on commits will use to
collapse the duplication.
@codspeed-hq

codspeed-hq Bot commented May 20, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 14 untouched benchmarks


Comparing bluetoothbot:koan/fix-issue-1738 (3b5403f) with master (4ff6540)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (f4b5066) during the generation of this report, so 4ff6540 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.77%. Comparing base (b22c8ff) to head (3b5403f).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1757   +/-   ##
=======================================
  Coverage   99.77%   99.77%           
=======================================
  Files          33       33           
  Lines        3497     3500    +3     
  Branches      489      490    +1     
=======================================
+ Hits         3489     3492    +3     
  Misses          5        5           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI test suite is very WET

1 participant