如何使用 pytest 在 python 中断言二进制多行值
how to assert a binary multiline value in python using pytest
我有以下使用 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.''
)
它似乎不起作用
提前感谢任何帮助。
使用三引号。原来的单行作业在单词 industry's
中有一个撇号的地方中断了。
assert file_pointer.get_value() == (
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.""")
我有以下使用 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.''
)
它似乎不起作用
提前感谢任何帮助。
使用三引号。原来的单行作业在单词 industry's
中有一个撇号的地方中断了。
assert file_pointer.get_value() == (
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.""")