python - 如何使用pytest在python中断言二进制多行值
问题描述
我有以下使用场景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.""")
推荐阅读
- node.js - 无法连接到 MongoDB 并出现错误 UnhandledPromiseRejectionWarning
- ffmpeg - FFMPEG 延迟多个叠加视频(具有不同的延迟)
- google-apps-script - 如何在 Google Apps 脚本中使用服务帐户验证 Google 表格
- mysql - MySQL 错误代码 1215:“无法添加外键约束”
- c# - 带有BackgroundService的QueueClient无法正常工作.NetCore2.2
- xml - 每次发布知识库后从 QnA Maker 中删除 XML 格式文本
- javascript - Redux Mock Store 给出 'Actions must be plain objects。使用自定义中间件进行异步操作。
- css - 如何在 ionic 中覆盖 app.scss 以外的 CSS 类?
- postgresql - 错误:无法加载库 ~/orafce.so:~/orafce.so:未定义符号:pq_sendbyte SQL 状态:XX000
- spring-boot - java - 如何在运行时在java类中选择spring选项参数