JoshData / python-email-validator

A robust email syntax and deliverability validation library for Python.
The Unlicense
1.14k stars 112 forks source link

test failure when DNS is not working #128

Closed htgoebel closed 8 months ago

htgoebel commented 9 months ago

In an attempt to work around #127 I created a dummy /etc/resolv.conf:

echo > /etc/resolv.conf nameserver 127.0.0.53

The named nameserver is not reachable. This leads to test failure:

====================================== FAILURES =======================================
______________________________ test_caching_dns_resolver ______________________________

    @pytest.mark.network
    def test_caching_dns_resolver():
        class TestCache:
            def __init__(self):
                self.cache = {}

            def get(self, key):
                return self.cache.get(key)

            def put(self, key, value):
                self.cache[key] = value

        cache = TestCache()
        resolver = caching_resolver(timeout=1, cache=cache)
        validate_email("test@gmail.com", dns_resolver=resolver)
>       assert len(cache.cache) == 1
E       assert 0 == 1
E        +  where 0 = len({})
E        +    where {} = <test_deliverability.test_caching_dns_resolver.<locals>.TestCache object at 0x7f0c1712fac0>.cache

tests/test_deliverability.py:78: AssertionError

Expected result

Tests pass even if nameserver is not reachable.

JoshData commented 8 months ago

This test actually just requires an Internet connection, so I've disabled it in the make test command.

If you're running tests another way, I recommend doing the same as in 306948daaf179229b722083f30460ce476a5fc76.

Thanks!