Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

should_not assertion message incorrect #18

Open
lerovitch opened this issue Apr 2, 2014 · 2 comments
Open

should_not assertion message incorrect #18

lerovitch opened this issue Apr 2, 2014 · 2 comments

Comments

@lerovitch
Copy link

>>> import mock
>>> spam = mock.MagicMock()
>>> spam.eggs({'foo': 'foo', 'bar': 'bar'})
>>> from pyshould import should_not
>>> spam.eggs.assert_called_with(should.be_dict.should_not.have_key('foo'))
AssertionError: Expected call: eggs(a dictionary containing key 'foo')
Actual call: eggs({'foo': 'foo', 'bar': 'bar'})

The message should say something like

AssertionError: Expected call: eggs(a dictionary not containing key 'foo')
Actual call: eggs({'foo': 'foo', 'bar': 'bar'})
@drslump
Copy link
Owner

drslump commented Apr 2, 2014

thanks for the report @lerovitch!

That a strange use case, although it should probably be supported too. The same can be accomplished with the following expression:

>>> spam.eggs.assert_called_with(should.be_dict.and_not_have_key('foo'))
AssertionError: Expected call: eggs((a dict and not a dictionary containing key 'foo'))
Actual call: eggs({'bar': 'bar', 'foo': 'foo'})

@lerovitch
Copy link
Author

well, omit the first assert

>>> import mock
>>> spam = mock.MagicMock()
>>> spam.eggs({'foo': 'foo', 'bar': 'bar'})
>>> from pyshould import should_not
>>> spam.eggs.assert_called_with(should_not.have_key('foo'))
AssertionError: Expected call: eggs(a dictionary containing key 'foo')
Actual call: eggs({'foo': 'foo', 'bar': 'bar'})

Also, thx for your advice as it's better to concatenate assertions with operators like 'and'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants