I'm working on a Django project but I think this is a pure Python unittest
question.
Normally, when you run tests, exceptions will be caught by the test runner and handled accordingly.
For debugging purposes, I want to disable this behavior, i.e. so that:
python -i manage.py test
will break into the interactive Python shell on an exception, as normal.
How to do that?
EDIT: based on the answers so far, it seems like this is more of a Django-specific question than I realized!
assertRaises(exception, callable, *args, **kwds) Test that an exception (first argument) is raised when a function is called with any positional or keyword arguments. The test passes if the expected exception is raised, is an error if another exception is raised, or fails if no exception is raised.
Alternate syntax for skipping test is using instance method skipTest() inside the test function.
An exception object is created when a Python script raises an exception. If the script explicitly doesn't handle the exception, the program will be forced to terminate abruptly.
Which is better – pytest or unittest? Although both the frameworks are great for performing testing in python, pytest is easier to work with. The code in pytest is simple, compact, and efficient. For unittest, we will have to import modules, create a class and define the testing functions within that class.
You can use django-nose test runner, it works with unittest
tests, and run your tests like python manage.py test -v2 --pdb
. And nose will run pdb for you.
A new app django-pdb makes this nicer, supporting a mode for breaking on test failures or uncaught exceptions in regular code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With