Dania
Dania

Reputation: 1017

Generating reports for tests in django

I am using django.test.TestCase based class methods for testing of my django application. When I execute the tests, it only shows the number of tests that are passed. What should I do to get output of which test got passed and which failed on console, just like the output of Proboscis framework. http://packages.python.org/proboscis/

That generates output like that..

$ python run_tests.py

test_should_return_false_for_positive_numbers (tests.examples.unit.tests.unit.TestIsNegative) ... ok
test_should_return_false_for_zero (tests.examples.unit.tests.unit.TestIsNegative) ... ok
test_should_return_true_for_negative_numbers (tests.examples.unit.tests.unit.TestIsNegative) ... ok
Make sure our complex string reversal logic works. ... ok

----------------------------------------------------------------------
Ran 4 tests in 0.001s

OK

But proboscis do not capture tests based on django.tests.TestCase class. Please advice me on what should I do now..

Upvotes: 2

Views: 4272

Answers (2)

rbashish
rbashish

Reputation: 2153

To generate a django tests result, follow the following steps:

  • Create a tests.py file under django app
  • Write all the test cases
  • Run the cmd from django project directory
    python manage.py test myApp.tests --verbosity=2 &> test-results.txt
    replace myApp with the name of your djanog app

To share the file with others you can generate a pdf of this file by opening it in browser and printing as save pdf.

&> symbol redirects both the standard output and standard error to the file

Upvotes: 0

sneawo
sneawo

Reputation: 3631

Run tests with verbosity option

python manage.py test --verbosity=2 app1 app2

-v VERBOSITY, --verbosity=VERBOSITY
                    Verbosity level; 0=minimal output, 1=normal output,
                    2=verbose output, 3=very verbose output

Upvotes: 2

Related Questions