【发布时间】:2014-12-20 18:13:12
【问题描述】:
我是 Python、PyCharm 和 Web API 测试领域的新手。
我正在尝试测试在 Web API 中出现错误时显示的错误消息。此错误消息有两个部分,并显示在两个单独的行上。
但不知何故,我为比较而生成的任何字符串定义总是显示在一行上。
这是我尝试过的事情之一 - 在两个部分之间创建了一个带有新行 \n 的字符串。
wp_error = 'This page can\'t be saved.\n Some required information is missing.'
# create new workspace and save it without filling up any information.
self.test_mycode.click_and_wait(self.workspace_overview.new_workspace_button,
self.new_workspace._save_button_locator)
self.new_workspace.save_button.click()
self.message.check_message('error', wp_error)
但这不起作用,我得到了:
在 check_message 中 Assert.equal(message.message_body.text, message_text)
self = <class 'unittestzero.Assert'>
first = "This page can't be saved.
Some required information is missing."
second = "This page can't be saved.\n Some required information is missing."
.....
> assert first == second, msg
E AssertionError: None
所以我的问题是如何定义字符串以适当地测试出现在两行上的错误消息? 谢谢。
【问题讨论】:
-
@user2864740,OP 的
wp_error行有什么问题? -
@PadraicCunningham 好电话,我误读了症状。