子进程未使用pytest错误处理测试运行



我目前正在将我的unittest设置转换为pytest,一切都在运行,但在某些测试中,我运行命令行进程,以便将代码加载到我通过USB连接的硬件中。这个过程在unittest中运行良好,但是当使用pytest或nose2时,我会得到的响应

------------------------------------------------ Captured stderr call -------------------------------------------------
Error processing Test

就在我的进程开始运行时发生这种情况?我没有收到错误消息是一个不确定为什么一个没有输出?该命令在cmd和unittest上运行时很好,是不是为了让它与pytest一起工作,我缺少了一些东西?

作为参考,我的班级正在运行

class LoadCode():
def __init__(self, comport):
''' Constructor
'''
self.filename = None   
self.code_comport = comport
self.code_loaded = False
self.logger = logging.getLogger(__name__)
def set_code_filename(self, new_file_name):
''' Sets the filename parameter for loading the code
'''
if (self.filename != new_file_name):  
self.filename = new_file_name
self.logger.info("Setting code File to " + self.filename)
self.code_loaded = False
else:
self.logger.info("Code File Name Is Already Set !")
def write_code(self):
REBOOT_TIME = 50 #approximatly 50 seconds if enough for a reboot after loading boot and main   and enough time for 
SUCCESSFUL_RETURNCODE = 0   # 0 is a successful return code for subprocess     
if(self.filename != None and self.code_comport != None):
#set up command line to run
command = <<COMMAND>>   
self.logger.info("Running: " + command)
#run command line as subprocess (thread will wait for command line to finish)              
load_code = subprocess.run(command)
#successful returncode = 0 anything else means an error has occured during subprocess               
subprocess.CompletedProcess(args=[command], returncode = SUCCESSFUL_RETURNCODE)
if (load_code.returncode == SUCCESSFUL_RETURNCODE ):
self.code_loaded = True
self.logger.info(self.filename) 
time.sleep(REBOOT_TIME)  #Allow reboot
else:
raise AssertionError("ERROR: No code File Set/No Comport Set")
self.is_code_loaded()
def is_code_loaded(self):
'''check the bool of code to ensure it has successfully ran
'''
if self.code_loaded == False:
Print("Failed")
raise AssertionError("Code Was Not Loaded ..")
else:
print("WORKED")
subprocess.CompletedProcess(args=[command], returncode = SUCCESSFUL_RETURNCODE)

这行代码不需要,因为它从subaccess.run((返回。感谢@Masklinn指出这一点。详细信息:https://python.readthedocs.io/en/latest/library/subprocess.html?highlight=CompletedProcess

生成的路径在中间包含空格,并且在开始时没有空格,这就是为什么命令没有运行并返回错误!现在,我的子流程可以很好地使用pytest和nose2!:(

相关内容

  • 没有找到相关文章

最新更新