Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call ipdb when a test fails in django testing?

I would like to start ipdb every time a test fails. I tried

$ ipython manage.py test myapp --pdb

but doesn't works.

like image 312
zVictor Avatar asked May 11 '12 18:05

zVictor


People also ask

How do I run a test case in Django?

Open /catalog/tests/test_models.py.TestCase , as shown: from django. test import TestCase # Create your tests here. Often you will add a test class for each model/view/form you want to test, with individual methods for testing specific functionality.

What is RequestFactory in Django?

The request factory The RequestFactory shares the same API as the test client. However, instead of behaving like a browser, the RequestFactory provides a way to generate a request instance that can be used as the first argument to any view.

How does Django do testing?

The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the Writing and running tests document. You can also use any other Python test framework; Django provides an API and tools for that kind of integration.


2 Answers

You can use the django-pdb app. Only install in your settings project

like image 152
Goin Avatar answered Nov 16 '22 02:11

Goin


If you pip install ipdbplugin and pip install django-nose, then add django_nose to your INSTALLED_APPS and set TEST_RUNNER = 'django_nose.NoseTestSuiteRunner', you can then call:

./manage.py test --ipdb

or

./manage.py test --ipdb-failures

See https://github.com/flavioamieiro/nose-ipdb and https://github.com/django-nose/django-nose for further details.

like image 23
Griffith Rees Avatar answered Nov 16 '22 00:11

Griffith Rees