[New-bugs-announce] [issue7956] unittest.Testcase assertDictContainsSubset with integer keys

Michael Newman report at bugs.python.org
Thu Feb 18 13:26:54 CET 2010


New submission from Michael Newman <michael.b.newman at gmail.com>:

The attached example unit test file shows that assertDictContainsSubset cannot handle error messages that need to show integer keys. Below is the output of the test suite, where "test_mixed_keys_fail" has an error (code mistake), while "test_text_keys_fail" produces a failure (result mistake) as expected.

C:\notes>C:\Python31\python.exe test_one_and_one.py
.E.F
======================================================================
ERROR: test_mixed_keys_fail (__main__.Test_one_and_one)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_one_and_one.py", line 30, in test_mixed_keys_fail
    self.assertDictContainsSubset({3: "this does not exist"}, self.dict_with_mix
ed_keys)
  File "C:\python31\lib\unittest.py", line 908, in assertDictContainsSubset
    standardMsg = 'Missing: %r' % ','.join(missing)
TypeError: sequence item 0: expected str instance, int found

======================================================================
FAIL: test_text_keys_fail (__main__.Test_one_and_one)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_one_and_one.py", line 33, in test_text_keys_fail
    self.assertDictContainsSubset({"3": "this does not exist"}, self.dict_with_t
ext_keys)
AssertionError: Missing: '3'

----------------------------------------------------------------------
Ran 4 tests in 0.010s

FAILED (failures=1, errors=1)

----------
components: Library (Lib)
files: test_one_and_one.py
messages: 99500
nosy: mnewman
severity: normal
status: open
title: unittest.Testcase assertDictContainsSubset with integer keys
type: behavior
versions: Python 3.1, Python 3.2
Added file: http://bugs.python.org/file16250/test_one_and_one.py

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7956>
_______________________________________


More information about the New-bugs-announce mailing list