From 5c7f4ba0489b735338a825970fce6b9b86f35dab Mon Sep 17 00:00:00 2001 From: Sean Whalen <44679+seanthegeek@users.noreply.github.com> Date: Sun, 26 Jul 2026 18:41:08 -0400 Subject: [PATCH] Clear shared IP cache in parallel test setUp for isolation (#866) tests/test_parallel.py's parity test compares sequential parse_report_file(path, offline=True) results in the parent process against results from cold worker processes. When the full suite runs locally (GITHUB_ACTIONS unset), tests/test_init.py runs first with real DNS lookups and warms the shared module-level parsedmarc.IP_ADDRESS_CACHE; get_ip_address_info consults the cache before honoring offline, so the sequential baseline returned DNS-enriched entries (e.g. reverse_dns='smtp7.cardinal.com') while the workers correctly returned None, failing the test. CI never sees this because it runs offline from the start. Clear the cache in _ParallelTestCase.setUp so baselines and workers both start cold. Test-only change; the cache-before-offline ordering in utils.py is intentional (a cache hit makes no network queries). Co-authored-by: Claude Fable 5 --- tests/test_parallel.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_parallel.py b/tests/test_parallel.py index 9e3e8b07..c9cf488e 100644 --- a/tests/test_parallel.py +++ b/tests/test_parallel.py @@ -47,7 +47,8 @@ class _CountingIterable: class _ParallelTestCase(unittest.TestCase): - """Common env setup shared by parallel.py tests: offline mode, no DNS.""" + """Common env setup shared by parallel.py tests: offline mode, no DNS, + and a cold IP address cache.""" def setUp(self): self._env_patcher = patch.dict( @@ -55,6 +56,13 @@ class _ParallelTestCase(unittest.TestCase): ) self._env_patcher.start() self.addCleanup(self._env_patcher.stop) + # Earlier test modules (e.g. tests/test_init.py) may run with DNS + # enabled locally and warm the shared module-level + # parsedmarc.IP_ADDRESS_CACHE. get_ip_address_info consults the + # cache before the offline check, so a warm cache would leak + # DNS-enriched entries into offline parses run in this process + # while spawned workers start cold, breaking parity. + parsedmarc.IP_ADDRESS_CACHE.clear() class TestParallelMapParseReportFile(_ParallelTestCase):