3

I don't know what I did, or what settings I messed with, but I've been using Pycharm for months now, and all of a sudden I stepped into some functionality that I can't get out of.

I'm still relatively new to python, so I set up a simple test of a Python object. I wanted to see if the object would get updated inside a called function...but that is beside the point. Somehow, through naming convention or something, I managed to convince Pycharm to switch to doing "nosetests" when I press debug or run...instead of running the code. The console outputs nothing...and the situation is impossible to google...

Anyhow, I did the following inside a Pycharm Python project:

I created a directory named scratch (there is an __init__.py file in it), and then a python file named scratch.py.

Inside scratch.py, I wrote the following code:

def add_item_function(x):
    x.list.append("hello,world")

class scratch(object):
    def __init__(self):
        self.list = []
    def add_item(self):
        add_item_function(self)

x = scratch()
add_item_function(x)
print(x.list)
y=1  #<-- here is where I put the breakpoint

And no matter what I do, the IDE only runs "nosetests" ... I tried putting the breakpoint in...and the code will actually hit the breakpoint on the debug...but the only output to the console pertains to the "nosetest" and not my code.

Further, I changed nothing. I have been doing this all the time--making classes and then running functions and code beneath them...and this has never happened before.


I found the configuration for the debugging...and Nosetests default to "scripts" in the project...but I can't disable it--it is a radio button. Some portion of my code apparently must be a nosetest...How do I toggle this/turn it off, and get the program to run the way I am telling it to?

Chris
  • 28,822
  • 27
  • 83
  • 158

3 Answers3

0

You may try to Edit Configurations: https://www.jetbrains.com/help/pycharm/2016.1/creating-and-editing-run-debug-configurations.html

one more suggestion is to use if __name__ == '__main__' to indicate it's the entry point, for more detais: What does if __name__ == "__main__": do?

Community
  • 1
  • 1
Guoliang
  • 885
  • 2
  • 12
  • 20
  • Just to add to this...PyCharm has different flavors of run configurations, including several flavors of test configuration. Nose is one of these, but you can also choose just plain unittest. I did [a video](https://www.youtube.com/watch?v=-VzJvNLooj4) to introduce this topic and [a more in-depth testing video](https://blog.jetbrains.com/pycharm/2016/04/in-depth-screencast-on-testing/). – Paul Everitt May 13 '16 at 12:22
0

I don't know whether suit to your situation. But under my coding, I just changed the name of my project and my class. I deleted all the 'test' or 'testing' in my code. Then I solved my problem... I think maybe pycharm is too smart to misunderstand our code...

0

Just click in the top left menu and when the dropdown appears select run again. It worked for me. More details here https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000413650-Disable-automatic-test-function

harapalb
  • 26
  • 4