3

I'm debugging a unit test failure whereby an exception is raised from the guts of some libraries; many exceptions. I'm using ipdb from the commandline to debug it.

when running ./manage.py test path.to.test and the exception happens, the test runner catches the exception, prints a stack trace and marks the test failed or whatever. I get why this is useful, rather than letting the exception rise.

In my case, I want it to rise so ipdb catches it and lands me in a nice position to move up/down frames and debug the issues. I don't want to keep wrapping tests in try or putting ipdb.set_trace() calls where the exceptions are thrown. It is a pain and it is slowing down debugging. Ordinarily this isn't an issue, but today it is.

Q: Can I stop the test runner catching the exception so ipdb catches it instead without code modifications?

I feel like there should be a way to do this, as it would be very helpful when debugging, but I have missed it somewhere along the line.

(Ps, Python 2.7, Django 1.6 sadface)

Aiden Bell
  • 28,212
  • 4
  • 75
  • 119
  • Is using pytest as your runner an option? https://docs.pytest.org/en/latest/usage.html#dropping-to-pdb-python-debugger-on-failures It has a specific option for bubbling to pdb. – Matt Seymour Jul 12 '17 at 14:49
  • Just out of curiosity... would using Pycharm be an option for you? You might find it much easier just to use this to set breakpoints – Sayse Jul 12 '17 at 14:52
  • 1
    @Sayse I am using charm, but for some reason (probably the huge size of the codebase) using charm's breakpoints and debugger is _stupidly_ slow to run the test. More time wasted, so I tend to just use ipdb. – Aiden Bell Jul 12 '17 at 14:56
  • 1
    @MattSeymour thanks for the hint, I will look at http://pytest-django.readthedocs.io/en/latest/ – Aiden Bell Jul 12 '17 at 14:59
  • https://stackoverflow.com/questions/1118183/how-to-debug-in-django-the-good-way/6880214 related – Aiden Bell Jul 12 '17 at 15:22

1 Answers1

1

There exist django-nose, a django unittest runner, which still has support for django 1.6 and python 2.7.

There is an --pdb option for nose which:

Drop into debugger on failures or errors

And you can run it as follows:

nosetests --pdb

Since you want to work with ipdb, there exist this nose plugin which allows nose to use ipdb:

nosetests --ipdb
John Moutafis
  • 22,254
  • 11
  • 68
  • 112