Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nosetest - get list of failed tests (without extra output)

Is it possible to have nose output only the name of the tests that fail to get a simple and compact list of failed tests?

I have figured out how to discard the captured stdout:

nosetests -s

but the assertion that fails is still printed (for example, assertEqual prints both the expected & actual values). Ideally I just want to know the file and line that failed.

like image 247
Felix Avatar asked Sep 07 '12 18:09

Felix


1 Answers

A very quick and primitive answer to your issue:

If you use --verbosity=2 parameter, it will list out all your tests

If you redirect stderr to stdout you can get a text file, something like this (example below would be run inside tests folder):

nosetests -s --verbosity=2 test_tasks.py > mytestresults.txt 2>&1

This will create a full list of all your tests and whether they pass or fail at the top of mytestresults.txt (you can trim off all the Assertion outputs, trace, etc. for failed tests after you get the list of tests from the top of mytestresults.txt).

Sample output below:

test_admin_users_can_complete_tasks_that_are_not_created_by_them (tests.test_tasks.TasksTests) ... ok

test_admin_users_can_delete_tasks_that_are_not_created_by_them (tests.test_tasks.TasksTests) ... ok

test_admin_users_can_see_task_modify_links_for_all_tasks (tests.test_tasks.TasksTests) ... FAIL

test_logged_in_users_can_access_tasks_page (tests.test_tasks.TasksTests) ... FAIL

test_not_logged_in_users_cannot_access_tasks_page (tests.test_tasks.TasksTests) ... ok

test_string_representation_of_the_task_object (tests.test_tasks.TasksTests) ... ERROR

test_task_template_displays_logged_in_user_name (tests.test_tasks.TasksTests) ... FAIL

test_users_can_add_tasks (tests.test_tasks.TasksTests) ... FAIL

test_users_can_complete_tasks (tests.test_tasks.TasksTests) ... FAIL

test_users_can_delete_tasks (tests.test_tasks.TasksTests) ... FAIL

test_users_can_see_task_modify_links_for_tasks_created_by_them (tests.test_tasks.TasksTests) ... FAIL

test_users_cannot_add_tasks_when_error (tests.test_tasks.TasksTests) ... FAIL

test_users_cannot_complete_tasks_that_are_not_created_by_them (tests.test_tasks.TasksTests) ... FAIL

test_users_cannot_delete_tasks_that_are_not_created_by_them (tests.test_tasks.TasksTests) ... FAIL

test_users_cannot_see_task_modify_links_for_tasks_not_created_by_them (tests.test_tasks.TasksTests) ... ok

... stack trace, etc. will be down here (not shown for brevity) ...

EDIT: oops I wrote this, saved, then noticed that you wanted the line number also. You would have to parse this out of the trace detail or a much more refined approach would be to use Nose-progressive plugin to format the output whatever way you like.

like image 192
Skyguard Avatar answered Sep 24 '22 13:09

Skyguard