This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 654c5e171d8 Make the SRV test fixture reset dns package attributes
(#73659)
654c5e171d8 is described below
commit 654c5e171d8e99ae4b8219c1a0f40b029bbec974
Author: Jarek Potiuk <[email protected]>
AuthorDate: Thu Sep 24 15:21:12 2026 +0200
Make the SRV test fixture reset dns package attributes (#73659)
stable_dns_import was meant to stop the SRV tests hitting real DNS when
another test's patch.dict(sys.modules, ...) leaves the dns package
attribute and sys.modules["dns.resolver"] pointing at different module
objects. It only re-imported the submodules, which is a no-op when they
are already in sys.modules, so the mismatch survived. On Python 3.11+
mock.patch("dns.resolver.resolve") patches the sys.modules copy while
the hook's `import dns.resolver` reads the package attribute, so
test_resolve_srv_targets_orders_by_priority made a real SRV query and
failed. The fixture now points dns.exception, dns.resolver and
dns.asyncresolver on the package at the modules in sys.modules.
Generated-by: Claude Opus 5
---
providers/http/tests/unit/http/hooks/test_http.py | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/providers/http/tests/unit/http/hooks/test_http.py
b/providers/http/tests/unit/http/hooks/test_http.py
index f3fc043ca78..db7d65ccf2d 100644
--- a/providers/http/tests/unit/http/hooks/test_http.py
+++ b/providers/http/tests/unit/http/hooks/test_http.py
@@ -696,14 +696,18 @@ class TestHttpHook:
@pytest.fixture
def stable_dns_import():
"""
- Re-import the ``dns`` submodules so ``sys.modules`` and the package
attributes agree.
-
- In CI, Python 3.10's ``mock.patch`` resolves dotted targets
attribute-first, so a stale attribute left
- by another test's ``patch.dict(sys.modules, ...)`` gets patched while the
hook re-imports a
- fresh module — bypassing the mock and hitting real DNS.
+ Point the ``dns`` package attributes at the submodules in ``sys.modules``,
so the two agree.
+
+ Another test's ``patch.dict(sys.modules, ...)`` can leave ``dns.resolver``
(the package attribute)
+ and ``sys.modules["dns.resolver"]`` referring to different module objects.
+ ``mock.patch("dns.resolver.resolve")`` and the hook's ``import
dns.resolver`` then resolve to
+ different objects - which one each picks depends on the Python version -
so the mock is bypassed
+ and the test hits real DNS. Importing the submodules again does not help,
because they are already
+ in ``sys.modules``; the package attributes must be reset.
"""
- importlib.import_module("dns.resolver")
- importlib.import_module("dns.asyncresolver")
+ dns = importlib.import_module("dns")
+ for name in ("exception", "resolver", "asyncresolver"):
+ setattr(dns, name, importlib.import_module(f"dns.{name}"))
@pytest.mark.usefixtures("stable_dns_import")