简体   繁体   English

VS代码中的Python单元测试调试

[英]Python Unit test debugging in VS code

I use VS code for my Python projects and we have unit tests written using Python's unittest module. 我在我的Python项目中使用VS代码,并且我们使用Python的unittest模块编写了单元测试。 I am facing a weird issue with debugging unit tests. 我在调试单元测试时遇到了一个奇怪的问题。

VSCode Version: May 2018 (1.24) VSCode版本:2018年5月(1.24)
OS Version: Windows 10 作业系统版本:Windows 10

Let's say I have 20 unit tests in a particular project. 假设我在一个特定的项目中有20个单元测试。

I run the tests by right clicking on a unit test file and click 'Run all unit tests' After the run is complete, the results bar displays how many tests are passed and how many are failed. 我通过右键单击单元测试文件来运行测试,然后单击“运行所有单元测试”。运行完成后,结果栏将显示通过了多少测试以及失败了多少。 (eg 15 passed, 5 failed). (例如15个通过,5个失败)。
And I can run/debug individual test because there is a small link on every unit test function for that. 我可以运行/调试单个测试,因为在每个单元测试功能上都有一个小链接。 If I re-run the tests from same file, then the results bar displays the twice number of tests. 如果我从同一文件重新运行测试,则结果栏将显示两倍的测试次数。 (eg 30 passed, 10 failed) (例如,通过30次,失败10次)
Also the links against individual test functions disappear . 与个别测试功能的链接也消失了 So I cannot run individual tests. 因此,我无法运行单个测试。
The only way to be able to run/debug individual tests after this is by re-launching the VS code. 此后能够运行/调试各个测试的唯一方法是重新启动VS代码。

Any suggestions on how to fix this? 对于如何解决这个问题,有任何的建议吗?

If anyone is still facing issue related to Unit Test debug and Run related issue in VS Code for Linux or Windows. 如果仍然有人遇到与Linux或Windows的VS Code中的单元测试调试和运行相关的问题。 Please follow these two steps. 请按照以下两个步骤。

  1. Download Latest Build From VSCode Repo Download Ling It will download a .vsix file which is an official extension to be added into next release. 从VSCode Repo下载最新版本。 下载Ling 。它将下载一个.vsix文件,这是一个官方扩展名,将添加到下一个版本中。

  2. Install the downloaded extension (.vsix) by using command code --install-extension myextension.vsix For more detail Read This How to install Click Here 使用命令code --install-extension myextension.vsix安装下载的扩展名(.vsix)。有关详细信息,请阅读此处如何安装,请单击此处。

I also faced a lot of issues and struggled a lot. 我也面临很多问题,也很挣扎。 So finally I raised an issue in the official GitHub repository. 所以最后我在官方GitHub存储库中提出了一个问题。 Check here Which helped me to solve the issue. 检查这里,这帮助我解决了问题。

这是VS代码的Python扩展的错误,现已修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM