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)

5
  • Is using pytest as your runner an option? docs.pytest.org/en/latest/… It has a specific option for bubbling to pdb. Commented Jul 12, 2017 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 Commented Jul 12, 2017 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. Commented Jul 12, 2017 at 14:56
  • 1
    @MattSeymour thanks for the hint, I will look at pytest-django.readthedocs.io/en/latest Commented Jul 12, 2017 at 14:59
  • stackoverflow.com/questions/1118183/… related Commented Jul 12, 2017 at 15:22

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

3 Comments

Looks promising, I will check this out, thanks for the answer +1
Good luck :) @AidenBell
No luck, 1.6 (at least the version we have ... vendored :( ) isn't compatible and working back through the django-nose versions yields no luck. Shame, might plug at it and try to find a workaround as a drop-in looks promising.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.