Disable automatic test function

已回答

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!!

 

5

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.

0

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

3

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).

3

Thank you, guys!!!

 

 

0

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.

2

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.

6

Now 2019 and still a stupid option.

0

This is annoying, can you please put a check box somewhere to remove this automatic test function detection?

3

Extremely annoying!!

1

Please change this behavior or make it configurable

1

Why not just leave both options there and stop choosing one for the users?

0
For me setting `Settings -> Tools -> Python Integrated tools -> Testing` to `Unittests` worked.  See SO post.
 
0

Using unittests under Python Integrated Tools. I get this for many modules which have no "import unittest", nor use test_ in the name.

A global disable, or a context "Run as script", or being able to turn doctests off from the "Modify Run Configuration" right click context menu would all be solutions.

Its really annoying having to keep going through menu Run>Run...

 

Great product overall though, switched from debugging Python  in VS Community (been an MS RAD disciple since Visual Basic 5.0!) and haven't looked back.

0

This also makes it a no-go to use the useful doctest feature of python, as the presence of a doctest in a file change ctrl-shift-F10 to mean run doctestst. (Even if the module has a if __name__ == "__main__ section (!!))

2

请先登录再写评论。