pythonmox

How do I use Python Mox to check if a method is called with the equivalent of a string?


I want to check if a function is being called with a string - however it seems that it makes a difference if that string is created using '%s' to insert a substring. The test is failing with this error:

UnexpectedMethodCallError: Unexpected method call.  unexpected:-  expected:+
- foo('Hello %s', 'world') -> None
?            ------
+ foo('Hello world') -> None

How do I check if the method is being called on 'Hello world', regardless of how the string was created?


Solution

  • There is no type or class like "formatted string" in the python. Just string. I think your have error in your code. I mean, it is your fault. I bet you are trying to call it like this:

    foo('Hello %s', 'world')
    

    But you should, instead, do

    foo('Hello %s' % 'world')
    

    Which will give you expected result.