0

I am using PyCharm to run a fairly sized test suite (1800 fast tests). 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. 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?

Andrés Marafioti
  • 819
  • 1
  • 7
  • 23

2 Answers2

1

Start a single test from the console

See the post Running single test from unittest.TestCase via command line.

Start it using 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 ...").

In the Unittests section of the Configuration folder you find the radio buttons All in folder, Script, Class, Method and Function. 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.

Community
  • 1
  • 1
Humbalan
  • 677
  • 3
  • 14
  • Wouldn't this actually make a test suite with the tests I input? If I write individually every class and method, it would equal to running the whole test suite, right? But It wouldn't run every testCase individually. – Andrés Marafioti Jul 05 '16 at 16:05
  • Assume you have at test script *myTest.py.* It contains the test cases `testClass1` and `testClass2`. They contain some test methods `testClass1.test_m1()` ... `testClass1.test_mn()` and `testClass2.test_m1()` ... `textClass2.test_mm()` and so on. As default pyCharm runs the whole test module. All test methods of all test cases. i. e. `testClass1.test_m1()` ... `testClass2.text_mm()`. To run a test e. g. `testClass1.text_mx()` individually select *method* in the debug configuration dialog as explained above. – Humbalan Jul 05 '16 at 18:16
0

There is another possibility for you to start the test methods in pyCharm individually. Run the complete test once. The "Run" window opens and on the left side there is a "TestResult" box wich logs each individual test. Wait for pyCharm having completet all the tests. Then rightclick the test method you want to execute and select Run 'test method' in the occurring popup.

Humbalan
  • 677
  • 3
  • 14
  • That is what I am doing, but it's manual. I'd like to run every test individually automatically. (Thanks for your help btw, I am going to try the method approach) – Andrés Marafioti Jul 05 '16 at 18:38
  • Could you please explain what you mean by "individually automatically"? For me "individually" means you trigger each test whenever you decide that it should run. "automatically" means, you trigger once and the whole test application runs until all the tests are finished. Perhaps an example will help. – Humbalan Jul 05 '16 at 19:59
  • I mean each testCase runs in it owns testSuite. "A test suite is a collection of test cases, test suites, or both. It is used to aggregate tests that should be executed together." In a testSuite, the type of mocking I show in the original post is persistent. Meaning once a method or class is mocked, it will remain mocked for the entirety of the test suite. – Andrés Marafioti Jul 06 '16 at 14:24