我遇到的问题是我在python(2.7)中使用mock
库,我发现这样的错误:
def raise_from(value, from_value):
> raise value
E AssertionError: Expected call: run_sync(country_code='GB', email_data={'username': 'username-1n@n3m((', 'hotelier_name': 'Alexander QW*!@H#(!*@#', 'id': 'hotel-id-8nabqtQW', 'hotelier_email': 'alexander@rnwmenrqnweq#!@#.com', 'name': 'hotel-name-8nabqtQW'}, i18n_labels=<MagicMock name='elami_labels' id='140095030265936'>, mail_service=<MagicMock name='mock.mail_service.users().messages()' id='140095028784272'>, partner_id='partner-facebooking-@j344', partner_name='partner-name-ANQWWEnn', product=<Product object at 0x7f6a6ad1da50>, username='username-1n@n3m((')
E Actual call: run_sync(country_code='GB', email_data={'username': 'username-1n@n3m((', 'hotelier_name': 'Alexander QW*!@H#(!*@#', 'id': 'hotel-id-8nabqtQW', 'hotelier_email': 'alexander@rnwmenrqnweq#!@#.com', 'name': 'hotel-name-8nabqtQW'}, i18n_labels=<MagicMock name='elami_labels' id='140095030265936'>, mailing_service=<MagicMock name='mock.mail_service.users().messages()' id='140095028784272'>, partner_id='partner-facebooking-@j344', partner_name='partner-name-ANQWWEnn', product=<Product object at 0x7f6a6ad1da50>, username='username-1n@n3m((')
这看起来很好,因为滚动,但在控制台中看起来更糟糕。像这样:
E AssertionError:预期电话:run_sync(country_code =&#39; GB&#39;,email_data = {&#39;用户名&#39;:&#39; username-1n @ n3m((&#39;, &#39; hotelier_name&#39;:&#39; Alexander QW *!@ H#(!* @#&#39;,&#39; id&#39;:&#39; hotel-id-8nabqtQW&#39; ;,&#39; hotelier_email&#39;:&#39; alexander @ rnwmenrqnweq#!@#。com&#39;,&#39; name&#39;:&#39; hotel-name-8nabqtQW&#39;} ,i18n_labels =,mail_service =,partner_id =&#39; partner-facebooking- @ j344&#39;,partner_name =&#39; partner-name-ANQWWEnn&#39;,product =,username =&#39; username-1n @ n3m((&#39;)
E实际通话:run_sync(country_code =&#39; GB&#39;,email_data = {&#39;用户名&#39;:&#39; username-1n @ n3m((&#39;,&# 39; hotelier_name&#39;:&#39; Alexander QW *!@ H#(!* @#&#39;,&#39; id&#39;:&#39; hotel-id-8nabqtQW&#39;, &#39; hotelier_email&#39;:&#39; alexander @ rnwmenrqnweq#!@#com&#39;,&#39; name&#39;:&#39; hotel-name-8nabqtQW&#39;},i18n_labels =,mailing_service =,partner_id =&#39; partner-facebooking- @ j344&#39;,partner_name =&#39; partner-name-ANQWWEnn&#39;,product =,username =&#39; username-1n @n3m ((&#39;)
即便如此,因为2条线没有对齐,所以很难发现差异。
有没有可以解决此问题的工具?我不擅长pytest扩展,但可能如果没有,我应该写一个 - 如果这甚至可能。我确信很多人一直都有这个问题。
或许还有某种方式,独立于py.test以显示这样的差异......一种快速解析调用并将其显示为错误的方法。
答案 0 :(得分:3)