Disable automatic test function

Answered

Hi,

I am using Pycharm. Recently, I notice that if word "test" in Python file, it will be run in test mode, like "nosetests". I just want regular running and debugging. 

Would you supply me some information about it?

 

Thank you!!

 

13 comments

You can still create a regular Python run configuration manually (Edit Configurations -> +), and point to your test_*.py files to execute them without the test runner.

1

This is a massive blocker for me as well... Manually creating run configurations by hand mean I have to create hundreds of them...

1

Hi Jp Senior! We are improving test detection in 2017.2 version. PyCharm is going to suggest to run scripts as pure Python if no special "test" syntax is found, e.g. test_* functions and so on.

As a workaround you can use Run | Run... action which suggest to choose between "as test" and "as script" execution. There's a special hotkey for it depending on your OS, on macOS it's Ctrl+Option+R.

This fix is going to be included in the next EAP build I believe (next week).

1

Thanks for your reply Pavel! It would be really great to have a global option to permanently disable this helpful 'test_' syntax detection as well :)  I don't really find the test_ suggestion helpful at all.

1

Jp Senior In fact it's more complex than that - in general for unittest there should be a class which is a subclass of unittest.TestCase with test_* methods and for nose/pytest PyCharm additionally introspects top level test_* functions searching for an assertion. I'll check if we have a ticket about global flag to disable this behaviour and will create a new one if there's none. Thank you for the feedback!

1

Thanks Pavel - this is the most clear description of how this feature works that I have seen so far in -- and now it's only in this comment thread, I greatly appreciate you helping me understand how this works.  This should be added to product documentation somewhere on the website.

In our large software product, we use many different python test mechanisms - doctest, nosetest, unittest.

I find it super helpful when I can run/debug specific tests (using unittest functionality) - but sometimes this function is not available because we subclass much of our test code...  When I do import unittest.TestCase I get these very helpful functions that let me re-run specific tests without having to run the entire python file - some of the tests are very expensive and take a few minutes to run.

On the other hand, some of my tests aren't compatible with the wrapper python uses around unittests / doctests, so I have to manually create run configurations. Alt-shift-F10 does let me run these tests as simple .py files, I just have to read the stdout when they run - this is okay for me.

The problem I have is a lack of flexibility within Pycharm to let me choose how to run the tests.  More often than not, I want to disable the unittest integration entirely as it only works with a small subset of our actual unit test code.

As I develop, I just want to press 'run' rapidly and make small configuration changes to the test code.  The keyboard shortcuts that I have to do 100% of the time are pretty slow still...

Certainly +1 for a feature request to turn off code test introspection....

Maybe a second +1 to force a file to run with the unittest/nosetest/pytest/doctest wrappers on as well with the ctrl-alt-f10 shortcut =)

 

 

2

I second this.  A global flag to disable test detection, or just a "Run as Script" option in the "Default Test Runner" dialogue would be very helpful.

I only seldom run pytest (a test server usually does this), but I frequently need to to run specific tests manually using the python interpreter to debug things.  

0

Still Can't figure out what is the problem to add classic 'RUN' option even when there are definitions with test_

It has been annoying me since forever.

0

It's there. Just right click a file > Run.

If that's not how it works for you - please attach a screenshot/screencast

 

0

There's no Run option. This is the menu I see when doing right click on the file:

Here's the build info:

It's highly annoying, if you could fix it it would be amazing, thanks.

 

0

Hi Nivhaa, there's a Run | Run ... option on the top menu bar.

1

Thanks Pavel, that worked. I join the voices above for a global flag to completely disable auto test detection.

1

Please sign in to leave a comment.