saghul / pycares

Python interface for c-ares
https://pypi.org/project/pycares/
MIT License
162 stars 74 forks source link

4.1.2: pytest is failing #167

Closed kloczek closed 2 years ago

kloczek commented 2 years ago

I'm trying to package your module as an rpm package. So I'm using the typical PEP517 based build, install and test cycle used on building packages from non-root account.

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.1.2-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.1.2-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra tests/tests.py
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pycares-pycares-4.1.2
plugins: cov-3.0.0, hypothesis-6.35.0
collected 54 items

tests/tests.py ........FFFFF.....xx.........s....................Fs..                                                                                                [100%]

================================================================================= FAILURES =================================================================================
_________________________________________________________________________ DNSTest.test_getaddrinfo _________________________________________________________________________

self = <tests.DNSTest testMethod=test_getaddrinfo>

    @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
    def test_getaddrinfo(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.getaddrinfo('localhost', 80, cb)
        self.wait()
        self.assertNoError(self.errorno)
>       self.assertEqual(type(self.result), pycares.ares_addrinfo_result)
E       AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>

tests/tests.py:52: AssertionError
________________________________________________________________________ DNSTest.test_getaddrinfo2 _________________________________________________________________________

self = <tests.DNSTest testMethod=test_getaddrinfo2>

    @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
    def test_getaddrinfo2(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.getaddrinfo('localhost', 'http', cb)
        self.wait()
        self.assertNoError(self.errorno)
>       self.assertEqual(type(self.result), pycares.ares_addrinfo_result)
E       AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>

tests/tests.py:65: AssertionError
________________________________________________________________________ DNSTest.test_getaddrinfo3 _________________________________________________________________________

self = <tests.DNSTest testMethod=test_getaddrinfo3>

    @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
    def test_getaddrinfo3(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.getaddrinfo('localhost', None, cb)
        self.wait()
        self.assertNoError(self.errorno)
>       self.assertEqual(type(self.result), pycares.ares_addrinfo_result)
E       AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>

tests/tests.py:78: AssertionError
________________________________________________________________________ DNSTest.test_getaddrinfo4 _________________________________________________________________________

self = <tests.DNSTest testMethod=test_getaddrinfo4>

    @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows')
    def test_getaddrinfo4(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.getaddrinfo('localhost', 'http', cb, family=socket.AF_INET)
        self.wait()
        self.assertNoError(self.errorno)
>       self.assertEqual(type(self.result), pycares.ares_addrinfo_result)
E       AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>

tests/tests.py:91: AssertionError
________________________________________________________________________ DNSTest.test_getaddrinfo5 _________________________________________________________________________

self = <tests.DNSTest testMethod=test_getaddrinfo5>

    def test_getaddrinfo5(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.getaddrinfo('google.com', 'http', cb)
        self.wait()
        self.assertNoError(self.errorno)
>       self.assertEqual(type(self.result), pycares.ares_addrinfo_result)
E       AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>

tests/tests.py:104: AssertionError
______________________________________________________ DNSTest.test_query_txt_multiple_chunked_with_non_ascii_content ______________________________________________________

self = <tests.DNSTest testMethod=test_query_txt_multiple_chunked_with_non_ascii_content>

    def test_query_txt_multiple_chunked_with_non_ascii_content(self):
        self.result, self.errorno = None, None
        def cb(result, errorno):
            self.result, self.errorno = result, errorno
        self.channel.query('txt-non-ascii.dns-test.hmnid.ru', pycares.QUERY_TYPE_TXT, cb)
        self.wait()
>       self.assertNoError(self.errorno)

tests/tests.py:342:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
tests/tests.py:42: in assertNoError
    self.assertEqual(errorno, None)
E   AssertionError: 11 != None
============================================================================= warnings summary =============================================================================
tests/tests.py::DNSTest::test_getaddrinfo
tests/tests.py::DNSTest::test_getaddrinfo2
tests/tests.py::DNSTest::test_getaddrinfo3
tests/tests.py::DNSTest::test_getaddrinfo4
tests/tests.py::DNSTest::test_getaddrinfo5
  /usr/lib/python3.8/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored from cffi callback <function _addrinfo_cb at 0x7fee640f7b80>: None

  Traceback (most recent call last):
    File "/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.1.2-2.fc35.x86_64/usr/lib64/python3.8/site-packages/pycares/__init__.py", line 162, in _addrinfo_cb
      result = ares_addrinfo_result(res)
    File "/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.1.2-2.fc35.x86_64/usr/lib64/python3.8/site-packages/pycares/__init__.py", line 841, in __init__
      cname_ptr = ares_addrinfo.cnames
  ffi.error: struct ares_addrinfo: wrong total size (cdef says 16, but C compiler says 24). fix it or use "...;" as the last field in the cdef for struct ares_addrinfo to make it flexible

    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))

-- Docs: https://docs.pytest.org/en/stable/warnings.html
========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/tests.py:421: ANY type does not work on Mac.
SKIPPED [1] tests/tests.py:528: The site used for this test no longer returns a non-ascii SOA.
XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6
  reason:
XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6_ll
  reason:
FAILED tests/tests.py::DNSTest::test_getaddrinfo - AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>
FAILED tests/tests.py::DNSTest::test_getaddrinfo2 - AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>
FAILED tests/tests.py::DNSTest::test_getaddrinfo3 - AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>
FAILED tests/tests.py::DNSTest::test_getaddrinfo4 - AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>
FAILED tests/tests.py::DNSTest::test_getaddrinfo5 - AssertionError: <class 'NoneType'> != <class 'pycares.ares_addrinfo_result'>
FAILED tests/tests.py::DNSTest::test_query_txt_multiple_chunked_with_non_ascii_content - AssertionError: 11 != None
===================================================== 6 failed, 44 passed, 2 skipped, 2 xfailed, 5 warnings in 21.68s ======================================================

BTW: without passing to pytest tests/tests.py it is not able to find units. Probably it would be good to add some testing description in pytest.ini.

saghul commented 2 years ago

What c-ares version do you have in your system?

I'm not familiar with pytest.ini, what should go in there?

kloczek commented 2 years ago

I'm using c-ares 1.18.1.

I'm not familiar with pytest.ini, what should go in there?

Firs it would be good to complete set of pytest parametrs which will be producing correct testtin (+ eventually some test suite corrections) than all cold be coded to pytest.ini to project.toml :)

kloczek commented 2 years ago

Gentle ping .. 😄

kloczek commented 2 years ago

Just FTR. New 4.2.0 still fails but in one unit less. Here is pytest output:

```console + PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.0-2.fc35.x86_64/usr/lib/python3.8/site-packages + /usr/bin/pytest -ra tests/tests.py =========================================================================== test session starts ============================================================================ platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0 rootdir: /home/tkloczko/rpmbuild/BUILD/pycares-pycares-4.2.0 collected 54 items tests/tests.py ........FFFFF.....xx.........s.................x..xs.. [100%] ================================================================================= FAILURES ================================================================================= _________________________________________________________________________ DNSTest.test_getaddrinfo _________________________________________________________________________ self = @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows') def test_getaddrinfo(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno self.channel.getaddrinfo('localhost', 80, cb) self.wait() self.assertNoError(self.errorno) > self.assertEqual(type(self.result), pycares.ares_addrinfo_result) E AssertionError: != tests/tests.py:52: AssertionError ________________________________________________________________________ DNSTest.test_getaddrinfo2 _________________________________________________________________________ self = @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows') def test_getaddrinfo2(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno self.channel.getaddrinfo('localhost', 'http', cb) self.wait() self.assertNoError(self.errorno) > self.assertEqual(type(self.result), pycares.ares_addrinfo_result) E AssertionError: != tests/tests.py:65: AssertionError ________________________________________________________________________ DNSTest.test_getaddrinfo3 _________________________________________________________________________ self = @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows') def test_getaddrinfo3(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno self.channel.getaddrinfo('localhost', None, cb) self.wait() self.assertNoError(self.errorno) > self.assertEqual(type(self.result), pycares.ares_addrinfo_result) E AssertionError: != tests/tests.py:78: AssertionError ________________________________________________________________________ DNSTest.test_getaddrinfo4 _________________________________________________________________________ self = @unittest.skipIf(sys.platform == 'win32', 'skipped on Windows') def test_getaddrinfo4(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno self.channel.getaddrinfo('localhost', 'http', cb, family=socket.AF_INET) self.wait() self.assertNoError(self.errorno) > self.assertEqual(type(self.result), pycares.ares_addrinfo_result) E AssertionError: != tests/tests.py:91: AssertionError ________________________________________________________________________ DNSTest.test_getaddrinfo5 _________________________________________________________________________ self = def test_getaddrinfo5(self): self.result, self.errorno = None, None def cb(result, errorno): self.result, self.errorno = result, errorno self.channel.getaddrinfo('google.com', 'http', cb) self.wait() self.assertNoError(self.errorno) > self.assertEqual(type(self.result), pycares.ares_addrinfo_result) E AssertionError: != tests/tests.py:104: AssertionError ============================================================================= warnings summary ============================================================================= tests/tests.py::DNSTest::test_getaddrinfo tests/tests.py::DNSTest::test_getaddrinfo2 tests/tests.py::DNSTest::test_getaddrinfo3 tests/tests.py::DNSTest::test_getaddrinfo4 tests/tests.py::DNSTest::test_getaddrinfo5 /usr/lib/python3.8/site-packages/_pytest/unraisableexception.py:78: PytestUnraisableExceptionWarning: Exception ignored from cffi callback : None Traceback (most recent call last): File "/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages/pycares/__init__.py", line 162, in _addrinfo_cb result = ares_addrinfo_result(res) File "/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.0-2.fc35.x86_64/usr/lib64/python3.8/site-packages/pycares/__init__.py", line 841, in __init__ cname_ptr = ares_addrinfo.cnames ffi.error: struct ares_addrinfo: wrong total size (cdef says 16, but C compiler says 24). fix it or use "...;" as the last field in the cdef for struct ares_addrinfo to make it flexible warnings.warn(pytest.PytestUnraisableExceptionWarning(msg)) -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html ========================================================================= short test summary info ========================================================================== SKIPPED [1] tests/tests.py:430: ANY type does not work on Mac. SKIPPED [1] tests/tests.py:537: The site used for this test no longer returns a non-ascii SOA. XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6 reason: XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6_ll reason: XFAIL tests/tests.py::DNSTest::test_query_txt_bytes2 reason: XFAIL tests/tests.py::DNSTest::test_query_txt_multiple_chunked_with_non_ascii_content reason: FAILED tests/tests.py::DNSTest::test_getaddrinfo - AssertionError: != FAILED tests/tests.py::DNSTest::test_getaddrinfo2 - AssertionError: != FAILED tests/tests.py::DNSTest::test_getaddrinfo3 - AssertionError: != FAILED tests/tests.py::DNSTest::test_getaddrinfo4 - AssertionError: != FAILED tests/tests.py::DNSTest::test_getaddrinfo5 - AssertionError: != ===================================================== 5 failed, 43 passed, 2 skipped, 4 xfailed, 5 warnings in 24.59s ====================================================== ```

There are some warnings which could be used to improve test suite.

kloczek commented 2 years ago

Closing. Looks like latest 4.2.1 version no longer fails

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.1-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pycares-4.2.1-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra tests/tests.py
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pycares-pycares-4.2.1
plugins: subtests-0.7.0, timeout-2.1.0
collected 54 items

tests/tests.py ..................xx.........s.................x..xs..                                                                                                [100%]

========================================================================= short test summary info ==========================================================================
SKIPPED [1] tests/tests.py:430: ANY type does not work on Mac.
SKIPPED [1] tests/tests.py:537: The site used for this test no longer returns a non-ascii SOA.
XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6
  reason:
XFAIL tests/tests.py::DNSTest::test_getnameinfo_ipv6_ll
  reason:
XFAIL tests/tests.py::DNSTest::test_query_txt_bytes2
  reason:
XFAIL tests/tests.py::DNSTest::test_query_txt_multiple_chunked_with_non_ascii_content
  reason:
================================================================ 48 passed, 2 skipped, 4 xfailed in 21.92s =================================================================