drslump / pyshould

Should style asserts based on pyhamcrest
MIT License
38 stars 7 forks source link

should_not assertion message incorrect #18

Open lerovitch opened 10 years ago

lerovitch commented 10 years ago
>>> 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 commented 10 years ago

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 commented 10 years ago

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'