简体   繁体   English

如何分别运行测试套件中的每个单元测试?

[英]how to run every unittest in a test suite individually?

I am using PyCharm to run a fairly sized test suite (1800 fast tests). 我正在使用PyCharm运行相当大的测试套件(1800个快速测试)。 Modifying a test recently, I realized my test would not break. 最近修改了一个测试,我意识到我的测试不会失败。 The do break when I run those tests individually, but if I run the whole test suite they will always pass. 当我单独运行这些测试时,do会中断,但是如果我运行整个测试套件,它们将始终通过。 This is due to this type of incorrect mocking of classes some previous co-workers did: 这是由于某些以前的同事对类进行的这种错误模拟:

import script

script.aClass = Mock()

I now need to check the usage of mocks in the whole test suite, but I would like to run every test individually and see which are the ones that are not passing (I will mark those as high priority). 现在,我需要检查整个测试套件中模拟的使用情况,但是我想单独运行每个测试,看看哪些没有通过(我将其标记为高优先级)。 How can I do this either from a console or from Pycharm? 如何从控制台或Pycharm中做到这一点?

Start a single test from the console 从控制台开始单个测试

See the post Running single test from unittest.TestCase via command line . 请参阅通过命令行从unittest.TestCase运行单个测试

Start it using pyCharm 使用pyCharm启动它

Supposing you have already a test for the complete module, please open the "Run/Debug Configurations" dialog in pyCharm (click on the test name in the tools bar, then click on "Edit Configuration ..."). 假设您已经对整个模块进行了测试,请在pyCharm中打开“运行/调试配置”对话框(单击工具栏中的测试名称,然后单击“编辑配置...”)。

In the Unittests section of the Configuration folder you find the radio buttons All in folder , Script , Class , Method and Function . Configuration文件夹的Unittests部分中,您可以在文件夹脚本方法函数中找到所有单选按钮。 Click on Method and input in the occuring fields Class and Method your test class name and the test class' method name respectively. 单击“ 方法”,然后在出现的“ 类”和“ 方法”字段中分别输入您的测试类名称和测试类的方法名称。 Click "OK" and run the test. 单击“确定”并运行测试。

There is another possibility for you to start the test methods in pyCharm individually. 您还可以单独在pyCharm中启动测试方法。 Run the complete test once. 运行一次完整的测试。 The "Run" window opens and on the left side there is a "TestResult" box wich logs each individual test. 将打开“运行”窗口,在左侧有一个“ TestResult”框,其中记录了每个测试。 Wait for pyCharm having completet all the tests. 等待pyCharm完成所有测试。 Then rightclick the test method you want to execute and select Run 'test method' in the occurring popup. 然后,右键单击要执行的测试方法 ,然后在出现的弹出窗口中选择“运行'测试方法”

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

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