Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling unittest.assertDictEqual for medium-size dictionaries takes too long #99151

Open
boaza opened this issue Nov 6, 2022 · 1 comment
Open
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@boaza
Copy link

boaza commented Nov 6, 2022

Calling assertDictEqual(d1, d2) / takes forever, even for medium-size dictionaries. To reproduce:

from unittest import TestCase
from random import randint

    def test_assert_dict(self):
        r = 10000000
        num = 10000
        d1 = dict((randint(0, r), randint(0, r)) for _ in range(num))
        d2 = dict((randint(0, r), randint(0, r)) for _ in range(num))
        self.assertDictEqual(d1, d2)

Probably related to issue #63416.

Tested on Python 3.10, Windows 11

@boaza boaza added the type-bug An unexpected behavior, bug, or error label Nov 6, 2022
@ronaldoussoren ronaldoussoren added the stdlib Python modules in the Lib dir label Dec 22, 2022
@ronaldoussoren
Copy link
Contributor

ronaldoussoren commented Dec 22, 2022

See also #51180 about slowness in difflib.ndiff (used by assertDictEquals to report about differences).

One avenue to explore would be to pick one of the other diff functions: unified_diff appears to be a lot faster, although this does change the output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants