【问题标题】:Getting extended information on Django unittest framework获取有关 Django unittest 框架的扩展信息
【发布时间】:2014-04-30 09:59:30
【问题描述】:

我正在使用 Django 单元测试框架来测试我的应用程序。 当我执行所有测试用例时,我会得到关于成功运行的测试用例的非常简短的信息。

----------------------------------------------------------------------
Ran 252 tests in 8.221s

OK

这是非常少的信息。我想了解有关每个测试用例的更多信息,

例如

每个测试用例执行所花费的时间。

成功完成每个测试模块。 等等等等。

我们是否有任何调试(或任何其他参数)参数可以启用有关已执行测试用例的扩展信息?

注意:- 使用详细参数不能满足我的需要

【问题讨论】:

    标签: django python-unittest django-unittest


    【解决方案1】:

    每个 django 命令都有一个--help 选项,如果你输入:

    python manage.py test --help你会看到命令test的所有可用选项:

    Options:
      -v VERBOSITY, --verbosity=VERBOSITY
                            Verbosity level; 0=minimal output, 1=normal output,
                            2=verbose output, 3=very verbose output
      --settings=SETTINGS   The Python path to a settings module, e.g.
                            "myproject.settings.main". If this isn't provided, the
                            DJANGO_SETTINGS_MODULE environment variable will be
                            used.
      --pythonpath=PYTHONPATH
                            A directory to add to the Python path, e.g.
                            "/home/djangoprojects/myproject".
      --traceback           Raise on exception
      --noinput             Tells Django to NOT prompt the user for input of any
                            kind.
      --failfast            Tells Django to stop running the test suite after
                            first failed test.
      --testrunner=TESTRUNNER
                            Tells Django to use specified test runner class
                            instead of the one specified by the TEST_RUNNER
                            setting.
      --liveserver=LIVESERVER
                            Overrides the default address where the live server
                            (used with LiveServerTestCase) is expected to run
                            from. The default value is localhost:8081.
      -t TOP_LEVEL, --top-level-directory=TOP_LEVEL
                            Top level of project for unittest discovery.
      -p PATTERN, --pattern=PATTERN
                            The test matching pattern. Defaults to test*.py.
      --version             show program's version number and exit
      -h, --help            show this help message and exit
    

    如您所见,您可以通过添加以下内容来设置详细级别:-v [level]

    尝试例如:python manage.py test -v 3

    【讨论】:

    • 感谢您的及时回复。但是这个参数对我没有帮助。我实际上已经尝试过了。它只给了我正在执行的测试用例的名称和测试用例的状态。我主要想把时间花在每个测试用例上。
    • 嗯,也许您可​​以编写自定义 TestRunner 以向日志中添加额外信息……但是……知道测试需要多少时间真的有帮助吗? (考虑到它们运行得非常非常快,而且那个时间并不是你的代码实现速度的可靠指标)
    • 实际上我们正在为我们的项目进行分布式开发。我认为这可能是一种计算某些功能所花费时间的方法。其实我在visual studio集成测试框架中已经使用过这个功能了。。各位有什么cmet可以给我指点一下吗?
    【解决方案2】:

    如果您想要每次测试的时间以及一些额外信息,请查看django-juno-testrunner 作为一个选项。我们希望从测试运行中获得更多信息,因此我们将其内置。

    请注意,目前它只是 Django 1.6+

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      • 2012-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多