![](/img/trans.png)
[英]Python: AssertionError when running nose tests with coverage
[英]Nose or pytest drop in to interactive console when running tests
在進行鼻子測試時,我想進入交互式控制台。 但是,如果我將以下內容放在代碼中:
import code
code.interact(local=locals())
鼻子僅打印(InteractiveConsole),不提供用於鍵入命令的控制台。 Pytest將code.interact視為失敗。 有沒有一種方法可以在運行測試時同時查看文件中的更改而進入控制台?
在pytest下獲得交互式會話的一種方法是使用以下方法設置斷點
import pdb
pdb.set_trace()
通常,pytest將禁止此交互式會話,並且在達到斷點時將掛起。 您可以通過使用-s
標志運行pytest來解決該問題,該標志禁用命令行輸出捕獲。
在最新版本的pytest中,您可以使用不帶-s
標志的pytest.set_trace()
來獲得相同的行為。 有關信息,請參閱文檔 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.