【问题标题】:nosetest - get list of failed tests (without extra output)nosetest - 获取失败的测试列表(没有额外的输出)
【发布时间】:2012-09-07 18:31:31
【问题描述】:

是否可以只让鼻子输出失败的测试的名称,以获得简单而紧凑的失败测试列表?

我已经想出了如何丢弃捕获的标准输出:

nosetests -s

但仍然会打印失败的断言(例如,assertEqual 会同时打印预期值和实际值)。理想情况下,我只想知道失败的文件和行。

【问题讨论】:

标签: python unit-testing nosetests


【解决方案1】:

对您的问题的一个非常快速和原始的答案:

如果您使用 --verbosity=2 参数,它将列出您的所有测试

如果您将 stderr 重定向到 stdout,您可以获得一个文本文件,如下所示(下面的示例将在 tests 文件夹中运行):

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

这将在mytestresults.txt 的顶部创建所有测试的完整列表以及它们是通过还是失败(在获得测试列表后,您可以删除所有失败测试的断言输出、跟踪等从mytestresults.txt 的顶部)。

下面的示例输出:

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) ...

编辑:哎呀,我写了这个,保存了,然后注意到你也想要行号。您必须从跟踪详细信息中解析出来,或者更改进的方法是使用Nose-progressive plugin 以您喜欢的方式格式化输出。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-20
    • 1970-01-01
    相关资源
    最近更新 更多