Running unit tests from context menu

Answered

I have unit tests for example in the following directory:

<project root>/foobar_source(source root)/foobar/tests/api/test_foobar.py

Inside the file, there is a

class TestFooBar(MyTestCaseChildClass):
    def test_foobar(self):
        <test code>

 

When I try

  • Right click on the Test Class
  • Right click on the test file in the Project view

There is no "Run unittests in ...." any more, just "Run ...". (Current PyCharm 2017.2 Professional)

 

Why are unit tests not being detected any more? What are the exact criterions for unit test detection?

 

 

6 comments
Comment actions Permalink

I noticed this issue as well, I was able to right click and run unittest from context menu directly after the latest update. 

One workaround here is to open the Run... menu and add an entry in "Python tests" manually and run once, then you will see run unittest when you right click on that test cases. But this must be something that needs fixing ASAP. 

0
Comment actions Permalink

Hi! Could you please try the latest EAP build? There're a couple of fixes related to test discovery. Has it helped? If no - please create a ticket in our bug tracker with more details about your layout, sample project to reproduce would be great.

0
Comment actions Permalink

This is strange, so I downloaded the EAP version and tried it. At first it still didn't work for that problematic test file, however, it works after I created another file and copy/paste the entire old file content to the new file. 

Not sure what happened, but since it is working now, I can live with that. 

0
Comment actions Permalink

You probably had run configuration for that old file to run it as pure Python (not test). And by default PyCharm suggests user to pick existed run configuration for given file instead of creating the new one. This blocks the ability to run file as test until the run configuration exists.

0
Comment actions Permalink

Similar problem in PyCharm 2017.3.3:

In a single session, while working in file test_a.py, at first I was able to select "run unittests..." from the context menu, now, suddenly, I cannot anymore. It's as if PyCharm no longer recognizes the unittests.

Still works for other test files...

How can this happen, all of a sudden?

Creating a unittest run-configuration manually works, but this still does not give me back the context menu options.

-edit-

Based on the implicit message in the post above, I tried deleting the existing "normal" run-configuration. That does the trick.

0
Comment actions Permalink

Had the same problem after updating to 2018.2, regression?

Updating to 2018.3 early access solved it for me.

0

Please sign in to leave a comment.