Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python pytest在断言错误后将测试标记为通过_Python_Testing_Pytest - Fatal编程技术网

Python pytest在断言错误后将测试标记为通过

Python pytest在断言错误后将测试标记为通过,python,testing,pytest,Python,Testing,Pytest,我正在尝试使用编写一个测试。我有一个服务,它可以用事件名和回调函数注册一个侦听器。在一段时间内,它生成数据并调用作为参数传递的回调。基本上,我需要评估回调中的一些断言,但即使断言失败,pytest也表示测试通过 def mytest(): service=MyService() def on_数据(数据): 断言错误 def on_end(): 打印(“全部完成”) service.on('data',on_data) 服务。on('端',on_端) service.start() 使用pyt

我正在尝试使用编写一个测试。我有一个服务,它可以用事件名和回调函数注册一个侦听器。在一段时间内,它生成数据并调用作为参数传递的回调。基本上,我需要评估回调中的一些断言,但即使断言失败,pytest也表示测试通过

def mytest():
service=MyService()
def on_数据(数据):
断言错误
def on_end():
打印(“全部完成”)
service.on('data',on_data)
服务。on('端',on_端)
service.start()
使用
pytest
运行此测试时,我得到:

错误断言为False
回溯[…]
断言错误
断言错误:断言错误
全部完成
通过
==========================================================1以10.67秒通过==============================

为什么测试被标记为通过?

请显示
MyService
code该服务是否在另一个进程中运行?在这种情况下,断言将不会传递给pytest。@MrBeanBremen MyService生成多个线程,回调将在其中一个线程中执行。这可能是问题吗?是的,这可能是问题所在。我没有测试多线程代码的经验,但这应该是一个已知的用例。