Skip to content

Fix failing unit tests #5190

@dchiquito

Description

@dchiquito

Summary

There are a number of tests currently failing on main:

  • test_unittest
  • test_urllib
  • test_userdict
  • test_uuid
  • test_webbrowser
  • test_xmlrpc
  • test_yield_from
  • test_zipfile

When these tests are run individually, they pass, which is why I assume they were not fixed sooner. When the entire test suite is run, they fail. Some experimentation reveals that there are a small number of apparently unrelated tests which "poison" these failing tests:

  • test_import and test_importlib
  • test_with
  • test_typing
  • test_mmap and test_os

Some failing tests are impacted by multiple "poisonous" tests.

test_import and test_importlib

These tests cause test_unittest to fail. If either is omitted or the order is changed, it will not fail:

RUSTPYTHONPATH=Lib cargo run --release -- Lib/test test_import test_importlib test_unittest

Stack trace:

test test_unittest failed -- Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/test_discovery.py", line 836, in test_discovery_failed_discovery
    with unittest.mock.patch('builtins.__import__', _import):
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/test_discovery.py", line 840, in test_discovery_failed_discovery
    with test.test_importlib.util.uncache('package'):
AttributeError: module 'test.test_importlib' has no attribute 'util'

test_with

test_with causes test_unittest, test_xmlrpc, and test_yield_from to fail:

RUSTPYTHONPATH=Lib cargo run --release -- Lib/test test_with test_unittest test_xmlrpc test_yield_from 

Stack trace for test_unittest:

test test_unittest failed -- Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_with.py", line 546, in failAsBool
    self.fail("Should NOT see this")
AssertionError: Should NOT see this

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/test_result.py", line 275, in test_addFailure_filter_traceback_frames_context
    self.assertEqual(len(dropped), 1)
AssertionError: 0 != 1

test_unittest failed

Stack trace for test_xmlrpc:

Exception occurred during processing of request from ('127.0.0.1', 35988)
Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 319, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 350, in process_request
    self.finish_request(request, client_address)
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 363, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 752, in __init__
    self.finish()
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 750, in __init__
    self.handle()
  File "/home/daniel/git/RustPython/pylib/Lib/socketserver.py", line 750, in __init__
    self.handle()
  File "/home/daniel/git/RustPython/pylib/Lib/http/server.py", line 427, in handle
    self.handle_one_request()
  File "/home/daniel/git/RustPython/pylib/Lib/http/server.py", line 419, in handle_one_request
    return
  File "/home/daniel/git/RustPython/pylib/Lib/http/server.py", line 393, in handle_one_request
    self.raw_requestline = self.rfile.readline(65537)
  File "/home/daniel/git/RustPython/pylib/Lib/socket.py", line 712, in readinto
    raise
  File "/home/daniel/git/RustPython/pylib/Lib/socket.py", line 705, in readinto
    return self._sock.recv_into(b)
ConnectionResetError: [Errno 104] Connection reset by peer (os error 104): 'None' -> 'None'
----------------------------------------
Warning -- threading_cleanup() failed to cleanup 0 threads (count: 0, dangling: 2)
Warning -- Dangling thread: <_MainThread(MainThread, started 1)>
Warning -- Dangling thread: <Thread(Thread-42 (run_server), stopped 43)>
test test_xmlrpc failed -- multiple errors occurred; run in verbose mode for details

Stack trace for test_yield_from

Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_with.py", line 546, in failAsBool
    self.fail("Should NOT see this")
AssertionError: Should NOT see this

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_yield_from.py", line 877, in test_throwing_GeneratorExit_into_subgen_that_raises
    self.assertIsInstance(e.__context__, GeneratorExit)
AssertionError: AssertionError('Should NOT see this') is not an instance of <class 'GeneratorExit'>

test_typing

This test causes 7 tests to fail: test_unittest, test_urllib, test_userdict, test_uuid, test_webbrowser, test_xmlrpc, test_zipfile

RUSTPYTHONPATH=Lib cargo run --release -- Lib/test test_typing test_unittest test_urllib test_userdict test_uuid test_webbrowser test_xmlrpc test_zipfile

Most of the stack traces are very similar:

Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/loader.py", line 130, in loadTestsFromModule
    return load_tests(self, tests, pattern)
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_unittest.py", line 8, in load_tests
    return unittest.test.suite()
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/__init__.py", line 17, in suite
    continue
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/__init__.py", line 15, in suite
    __import__(modname)
  File "_frozen_importlib", line 1461, in __import__
  File "_frozen_importlib", line 1382, in _gcd_import
  File "_frozen_importlib", line 1352, in _find_and_load
  File "_frozen_importlib", line 1355, in _find_and_load
  File "_frozen_importlib", line 1329, in _find_and_load_unlocked
  File "_frozen_importlib", line 1326, in _find_and_load_unlocked
  File "_frozen_importlib", line 1326, in _find_and_load_unlocked
  File "_frozen_importlib", line 945, in _load_unlocked
  File "_frozen_importlib", line 943, in _load_unlocked
  File "_frozen_importlib", line 936, in _load_unlocked
  File "_frozen_importlib", line 930, in _load_unlocked
  File "_frozen_importlib_external", line 994, in exec_module
  File "_frozen_importlib", line 488, in _call_with_frames_removed
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/test/test_discovery.py", line 12, in <module>
    import unittest.mock
  File "/home/daniel/git/RustPython/pylib/Lib/unittest/mock.py", line 1060, in <module>
    _MOCK_SIG = inspect.signature(NonCallableMock.__init__)
  File "/home/daniel/git/RustPython/pylib/Lib/inspect.py", line 3096, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
  File "/home/daniel/git/RustPython/pylib/Lib/inspect.py", line 2846, in from_callable
    follow_wrapper_chains=follow_wrapped)
  File "/home/daniel/git/RustPython/pylib/Lib/inspect.py", line 2296, in _signature_from_callable
    skip_bound_arg=skip_bound_arg)
  File "/home/daniel/git/RustPython/pylib/Lib/inspect.py", line 2206, in _signature_from_function
    __validate_parameters__=is_duck_function)
  File "/home/daniel/git/RustPython/pylib/Lib/inspect.py", line 2813, in __init__
    for param in parameters))
  File "/home/daniel/git/RustPython/pylib/Lib/collections/__init__.py", line 115, in __init__
    self.__update(other, **kwds)
  File "/home/daniel/git/RustPython/pylib/Lib/_collections_abc.py", line 980, in update
    if isinstance(other, Mapping):
  File "/home/daniel/git/RustPython/pylib/Lib/_py_abc.py", line 105, in __instancecheck__
    return cls.__subclasscheck__(subclass)
  File "/home/daniel/git/RustPython/pylib/Lib/_py_abc.py", line 142, in __subclasscheck__
    if issubclass(subclass, scls):
  File "/home/daniel/git/RustPython/pylib/Lib/_py_abc.py", line 123, in __subclasscheck__
    ok = cls.__subclasshook__(subclass)
  File "/home/daniel/git/RustPython/pylib/Lib/typing.py", line 1564, in _proto_hook
    raise TypeError("Instance and class checks can only be used with"
TypeError: Instance and class checks can only be used with @runtime_checkable protocols

test_mmap and test_os

Similarly to test_import and test_importlib, if both of these tests are run before test_zipfile, it will fail. If either are omitted the order is changed, test_zipfile will pass.

RUSTPYTHONPATH=Lib cargo run --release -- Lib/test test_mmap test_os test_zipfile

Stack trace:

test test_zipfile failed -- Traceback (most recent call last):
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_zipfile.py", line 2573, in test_many_opens
    with open(os.devnull, "rb") as f:
  File "/home/daniel/git/RustPython/pylib/Lib/test/test_zipfile.py", line 2574, in test_many_opens
    self.assertLess(f.fileno(), 100)
AssertionError: 104 not less than 100

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions