Skip to content

TypeError when patching a dictionary with a Unicode string literal on Python 2 #458

Closed
@micbou

Description

@micbou

Patching a dictionary with a Unicode string literal on Python 2 raises the exception TypeError: string indices must be integers. Running a test.py file containing the following code

from mock import patch

some_dict = {}

with patch.dict(u'test.some_dict'):
    pass

results in

Traceback (most recent call last):
  File "test.py", line 5, in <module>
    with patch.dict(u'test.some_dict'):
  File "C:\Python27\lib\site-packages\mock\mock.py", line 1766, in __enter__
    self._patch_dict()
  File "C:\Python27\lib\site-packages\mock\mock.py", line 1783, in _patch_dict
    original[key] = in_dict[key]
TypeError: string indices must be integers

This is a regression introduced by commit 5268eda.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions