python / python/cpython

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

Open
#99,151 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Linked PRs
  • gh-126923

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Python reproduction and inspect unittest.assertDictEqual, then read issue #63416 and linked PR gh-126923 for existing context. Done means the medium-size dictionary comparison no longer takes an excessive amount of time, with the behavior checked against the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.