hRobert12 / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Call stack on function calls making changes to dictionary fails at assertions of arguments because the dictionary changes. #238

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
mkdir testcase
place mod.py into testcase
cd testcase
mkdir tests
place test_mod.py into tests

pip install mock nose
run nosetests

Actual behavior:
======================================================================
FAIL: test_func_c (test_mod.FooBarTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/bretttrotter/.virtualenvs/testcase/lib/python2.7/site-packages/mock.py", line 1201, in patched
    return func(*args, **keywargs)
  File "/Users/bretttrotter/testcase/tests/test_mod.py", line 21, in test_func_c
    'mocked_a': 'func_a'
  File "/Users/bretttrotter/.virtualenvs/testcase/lib/python2.7/site-packages/mock.py", line 835, in assert_called_with
    raise AssertionError(msg)
AssertionError: Expected call: func_b({'mocked_a': 'func_a'})
Actual call: func_b({'mocked_a': 'func_a', 'b': {'mocked_b': 'func_b'}})
-------------------- >> begin captured stdout << ---------------------
CODE: Data at this time is exactly what we think:
{'mocked_a': 'func_a'}
TEST: This assertion matches the print, but fails

--------------------- >> end captured stdout << ----------------------

----------------------------------------------------------------------
Ran 1 test in 0.006s

FAILED (failures=1)

shell returned 1

Expected behavior:
This is something of a philosophical debate:
- My argument is that the print statement verifies my assertion is true and the 
assertion failing to match up is a bug. 
- I understand that the call stack is probably pointing at a dictionary that 
gets updated, but I'd argue the call stack should save a copy/snapshot of the 
dictionary at that time.
- Said another way- if I'm printing out what it's actually being called with 
and i assert that it was called with what it's actually being called with, and 
it fails, that that's a problem/mistake/bug.

Original issue reported on code.google.com by brett.tr...@workiva.com on 19 Aug 2014 at 6:54

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
This topic is covered in the documentation: 

http://mock.readthedocs.org/en/latest/examples.html#coping-with-mutable-argument
s

Original comment by fuzzyman on 20 Aug 2014 at 6:21