2

I have the following problem :

I am doing some unit tests but the problem is that I cannot use the debugger I tried to click on "Debug namefile" using a breakpoint but it does not work. Alternatively, I tried to use tyhe following decorator @override_settings(DEBUG=True) but once again I had no result using this way.

I precise that it is only with unit tests I have this kind of problems. The other part of the code works well.

Could you help me please ?

PS: to do the unit test I imported TestCase from django.test.

Thank you very much !

  • What do you mean by "it does not work"? What *PyCharm* version are you using? – CristiFati Aug 30 '19 at 12:40
  • I mean It is like I click on Run without the mode debug active – Peter Julian Aug 30 '19 at 12:45
  • That doesn't clear things up. Please add more details (maybe even screenshots), as described in [\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/mcve). – CristiFati Aug 30 '19 at 12:52
  • So you click on `Debug Unittests for test_...` command in the sidebar next to your test? And in the bottom console, the name of the tab that opens is "Debug"? – dirkgroten Aug 30 '19 at 13:57
  • And you're sure the "Mute breakpoints" option isn't activated? (little red circle with a slash) – dirkgroten Aug 30 '19 at 13:59
  • Somehow related: https://stackoverflow.com/questions/42989471/run-debug-a-django-applications-unittests-from-the-mouse-right-click-context. – CristiFati Aug 31 '19 at 13:01

2 Answers2

2

I used to have same problem with PyCharm+Django when running python manage.py test from command line. I solved it by creating new configuration for test.

enter image description here

Mainly, you will need to fill "Script path" (path to manage.py) and "Parameters". enter image description here

Then, run debug with that configuration and breakpoints in Django tests will work.

Pyae
  • 430
  • 1
  • 4
  • 13
0

PyCharm menu:

Run / Edit configuration / Add Django test / Add Target and options.

For example, here is a mapping from command line to GUI fields,

Run just one test method

./manage.py test --keepdb animals.tests.AnimalTestCase.test_animals_can_speak

Target: animals.tests.AnimalTestCase.test_animals_can_speak

options: --keepdb

.

Ref, https://www.jetbrains.com/help/pycharm/2020.1/run-debug-configuration-django-test.html

Charlie 木匠
  • 1,450
  • 12
  • 18