Export to GitHub

mock - issue #245

assert_called_with scope issues


Posted on Feb 3, 2015 by Happy Horse

What steps will reproduce the problem? from mock import patch

def foobar(): data = { 'first_name': 'Foo', 'last_name': 'Bar', 'title': 'Mr' } print_data(data) data['address'] = 'homeless'

def print_data(data): print data

@patch('main.print_data') def test_foobar(mock_print_data): data = { 'first_name': 'Foo', 'last_name': 'Bar', 'title': 'Mr' } foobar() mock_print_data.assert_called_with(data)

test_foobar()

What is the expected output? What do you see instead?

Expected output is that the call is made with data and the test passes.

What happens is an assertion error is raised with the data that was appended AFTER the call being the culprit:

AssertionError: Expected call: print_data({'first_name': 'Foo', 'last_name': 'Bar', 'title': 'Mr'}) Actual call: print_data({'first_name': 'Foo', 'last_name': 'Bar', 'address': 'homeless', 'title': 'Mr'})

What version of the product are you using? On what operating system? mock - 1.0.1 osx - 10.10.2 python - 2.7.9

Please provide any additional information below.

Status: New

Labels:
Type-Defect Priority-Medium