Aiden Bell
Aiden Bell

Reputation: 28386

Django/Python Unit Testing: Let exceptions rise

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)

Upvotes: 3

Views: 134

Answers (1)

John Moutafis
John Moutafis

Reputation: 23134

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

Upvotes: 1

Related Questions