Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use --failfast in django test command line?

I want to use --failfast so that if my one test fail, remaining all other test gets executed. Do I need to create new test runner or I can use it in command line ?

like image 228
Pratik Bhatt Avatar asked Dec 21 '16 18:12

Pratik Bhatt


People also ask

How do I run a test in Django?

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.

How do you write unit test cases in Django?

To write a test you derive from any of the Django (or unittest) test base classes (SimpleTestCase, TransactionTestCase, TestCase, LiveServerTestCase) and then write separate methods to check that specific functionality works as expected (tests use "assert" methods to test that expressions result in True or False values ...

What is RequestFactory in Django?

The request factory The API for the RequestFactory is a slightly restricted subset of the test client API: It only has access to the HTTP methods get() , post() , put() , delete() , head() , options() , and trace() . These methods accept all the same arguments except for follow .

Where does Django store test database?

from the docs: When using SQLite, the tests will use an in-memory database by default (i.e., the database will be created in memory, bypassing the filesystem entirely!).


1 Answers

Add the --failfast flag if you WANT all the other tests to stop, as documented here in the official django documentation:

python manage.py test --failfast

But it sounds like you want it to do the opposite of what failfast does, which is to keep going, and that is the default behavior when you run django tests without flags:

python manage.py test

If that is not your default, it may be that your project has already overridden the default behavior in some settings or TestRunner class.

like image 95
LisaD Avatar answered Nov 10 '22 17:11

LisaD