我在PyCharm社区3.4.1中使用Python 2.7和unittest2.我需要将CLI命令的文本输出与字符串的内容进行匹配以进行自动测试.
该命令的输出通常在行尾有尾随空格; 如果我在我用来存储预期文本的heredoc中的行末尾添加空格,它们会在编辑器中神秘地被删除而不会进入文件.为了解决这个问题,我不得不将我的heredoc分开并用空格重新组合; 这非常难看,但这是我能让它发挥作用的唯一方法.
我试过谷歌搜索并寻找解释,但我没有找到; 我怀疑可能是PyCharm的autoformatting混淆并将其视为一行Python代码,可以安全地删除尾随空格.
这是我的代码; 它在unittest2类中:
def test_help_command(self):
textgot = run_the_help_command()
partone = """
blah blaah blah blah blah
This line has a space at the end in the help output"""
parttwo = """
foo foo foo foo foo
This line also ends with a trailing space in the help output"""
partthree = """
baz baz baz
"""
# Recombine parts with spaces
helptext = partone + " " + parttwo + " " + partthree
self.assertMultiLineEqual(helptext, …Run Code Online (Sandbox Code Playgroud)