with_matching_args() should fail on missing keyword args?

Create issue
Issue #25 new
Gary Johnson created an issue

I noticed that with_matching_args() will succeed if I expect a keyword arg and the method is called without that arg at all. Only when the method is called with the expected keyword arg but doesn't match does an assertion get thrown.

I would expect failure to be the default behavior in this case, and was getting ready to submit a pull request, but I noticed a test specifically for this scenario (test_missing_matching_keyword_args_is_ok) so I wanted to understand the use case for this.

If I say fake.expects('method').with_matching_args(my_arg='value'), and I call method(), shouldn't that fail the assertion? What is the case for this not failing?

My issue is that I would like to ensure that a single arg is provided with a certain value, but I do not want to specify all arguments using with_args() and arg.any(), as that creates noise that obscures the purpose of the test, and is brittle and needs to be changed whenever the args passed into the method change.

If this behavior is important to maintain, should there be another call (with_all_matching_args? etc) that fails in this case?

Comments (0)

  1. Log in to comment