JoshData / python-email-validator

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

test failure when /etc/resolve.conf is missing #127

Closed htgoebel closed 9 months ago

htgoebel commented 9 months ago

When running the tests in a container/chroot, where /etc/resolv.conf is missing, test error:

======================================= ERRORS ========================================
____________________ ERROR collecting tests/test_deliverability.py ____________________
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:782: in read_resolv_conf
    f = stack.enter_context(open(f))
E   FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'

During handling of the above exception, another exception occurred:
tests/test_deliverability.py:10: in <module>
    RESOLVER = MockedDnsResponseData.create_resolver()
tests/mocked_dns_response.py:35: in create_resolver
    return caching_resolver(cache=MockedDnsResponseData.INSTANCE)
email_validator/deliverability.py:13: in caching_resolver
    resolver = dns.resolver.Resolver()
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:734: in __init__
    self.read_resolv_conf(filename)
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:785: in read_resolv_conf
    raise NoResolverConfiguration
E   dns.resolver.NoResolverConfiguration: Resolver configuration could not be read or specified no nameservers.
_________________________ ERROR collecting tests/test_main.py _________________________
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:782: in read_resolv_conf
    f = stack.enter_context(open(f))
E   FileNotFoundError: [Errno 2] No such file or directory: '/etc/resolv.conf'

During handling of the above exception, another exception occurred:
tests/test_main.py:9: in <module>
    RESOLVER = MockedDnsResponseData.create_resolver()
tests/mocked_dns_response.py:35: in create_resolver
    return caching_resolver(cache=MockedDnsResponseData.INSTANCE)
email_validator/deliverability.py:13: in caching_resolver
    resolver = dns.resolver.Resolver()
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:734: in __init__
    self.read_resolv_conf(filename)
/gnu/store/796pv4r9rixyvcqwd5q7bbbybhc0dk48-python-dnspython-2.1.0/lib/python3.10/site-packages/dns/resolver.py:785: in read_resolv_conf
    raise NoResolverConfiguration
E   dns.resolver.NoResolverConfiguration: Resolver configuration could not be read or specified no nameservers.

The example above stems from trying to run the tests as part of building a Guic package. Guix (like nix) build packages in a very slim container.

Expected result

Tests pass even if /etc/resolv.conv does not exist.

JoshData commented 9 months ago

Thanks, hopefully now fixed!