PyCharm's pytest runner not available for all tests

Answered

My project is laid out this way:

lib/

   module_a/

       tests/

             integration/

                 test_integration_a.py

             unit/

                 test_unit_a.py

   module_b/

       tests/

             integration/

                 test_integration_a.py

             unit/

                 test_unit_a.py

src

   module_c/

       tests/

             integration/

                 test_integration_a.py

             unit/

                 test_unit_a.py

 

If I right click any of the tests folders, I get an option to run pytests. However,I can only run tests on subfolders, modules, classes, and functions on module_a. I don't see the option to run tests for the other modules.

Help?

6 comments

Hello.

Can you please create project to reproduce and create issue in issue tracker https://youtrack.jetbrains.com/ or contact JetBrains support by email?

0

With 2018.3 it appears to automatically detect that I'm using pytest, which is nice, but it still doesn't allow running from the top level of the project. I had to run each test individually. However, I found that I could choose one of the configurations and manually edit it to run at the root of the project and that this worked. I have to manually choose it in the Configurations drop-down - can't right click on the root folder in the Project pane. But at least it allows me to run all tests at once.

 

0

Hi Jcrotinger,

Is it possible to provide some sample project?

I can perfectly well right click my project folder and run all pytests in it.

0

Hi Sergey,

In sqlalchemy all tests are under a single tests tree. My project, like the one above, has tests co-located with sub-modules. So I have something like:

```

my_package/

    tests/

    my_sub_package_a/

          tests/

    my_sub_package_b/

          tests/

```

Etc.

This is a not uncommon pattern that keeps the tests with the parts being tested, instead of arranged in a parallel tree. It would be nice if PyCharm recognized this pattern and allowed me to right-click on `my_package` and see the ‘run pytests’, etc., actions, effectively creating the pytest configuration that I created by hand.

Thanks!

        Jim

 

0

Hi Jim,

Sorry, I should have noted at it at first. There is indeed no such option in the context menu if the folder doesn't have tests in it, or the name of the folder doesn't contain test word.

So if you add test word to a needed folder, then it will allow you to run tests from it's context menu.

It is still possible to run tests even if folder name doesn't have test word or if folder doesn't have any tests inside, but it should be achieved via setup.py file. I cannot tell you the exact procedure, but you can check setup.py of the following project https://github.com/zzzeek/sqlalchemy

0

Thanks @Sergey - might consider it as a feature request since it seems like a pretty common pattern.

Cheers - Jim

 

0

Please sign in to leave a comment.