How to debug faster with Python + Django + PyCharm on Windows?

Debugging Django with PyCharm.

When I run anything in the debugger it is slow.

Django's startup time is quite long.

Don't get me wrong - I love PyCharm as it has all the bells and whistles you need for a comfortable debugging session ... and Python is still easier and probably faster to debug than other languages ​​(like C), but even after of how I set up my PostgreSQL database for testing ( Optimize PostgreSQL for quick testing ) even if I have an SSD drive and an i7 quad core processor, even if I specifically told my antivirus software NOT to touch anything in the C: \ directory Python27 and my project, it is still very slow.

Any ideas how I can speed up debugging?

I would like to see improvements mainly during process startup, because my most frequently used case is when I am debugging a single unit test.

+3


source to share


2 answers


Start python, but use pdb for your code. Something like that:

... code before ...
import pdb; pdb.set_trace()
... code after ...

      



It will stop the code at this point. You will need to press c (continue), q (quit), or n (next) to continue driving. You can check expressions and check where you are by pressing l.

The code will be faster, but debugging can be more painful.

+3


source


I had the same problem a while ago, until I figured out that Django and PyCharm allow you to specify to run single tests, rather than the full test suite every time I press the debug button.

To do this, just edit the Debug config in PyCharm. Change target

to point to a module, class, or even a method somewhere deep in your test files.

To do this, make sure your directories are modules (for example, the directory that contains the __init__.py file). Now you can specify specific goals in the following format:



django_app.tests_module.test_case.test_method

      

It is clear that the final target "path" depends on your project organization.

Don't forget to change the target after you're done with the implementation to run all tests before pushing your code;)

+1


source







All Articles