【发布时间】:2021-12-11 04:54:03
【问题描述】:
我有以下使用python3的场景:
type(file_pointer)
=> <class '_io.BytesIO'>
然后
file_pointer.get_value()
# result below
b'simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.'
根据python 和pytest 声明上述内容的好方法是多行
我试过了:
assert file_pointer == (
'b'simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the'
'industry's standard dummy text ever since the 1500s, when an unknown printer took a'
'galley of type and scrambled it to make a type specimen book. It has survived not only'
'five centuries, but also the leap into electronic typesetting, remaining essentially'
'unchanged. It was popularised in the 1960s with the release of Letraset sheets'
'containing Lorem Ipsum passages, and more recently with desktop publishing software'
'like Aldus PageMaker including versions of Lorem Ipsum.''
)
它似乎不起作用
任何帮助都会有所帮助,提前致谢。
【问题讨论】:
-
断言整个内容始终相同?
-
"基于它是多行的事实" 这似乎并非如此。
file_pointer.get_value()中没有换行符。不过,您的参考字符串缺少空格。
标签: python python-3.x pytest stringio