【问题标题】:Running Django test with setup.py test and tox使用 setup.py test 和 tox 运行 Django 测试
【发布时间】:2013-11-07 03:08:12
【问题描述】:

我构建了一个 Django 应用程序并使用 setuptools 制作了一个包。现在,我想做以下事情:

  1. 我想使用python setup.py test 运行所有测试。但是当我发出这个命令时,我得到:

    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
    warnings.warn(msg)
    usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
    or: setup.py --help [cmd1 cmd2 ...]
    or: setup.py --help-commands
    or: setup.py cmd --help
    
    error: invalid command 'test'
    
  2. 我想使用 Tox 来运行我的测试,但我不知道应该在 command 属性中写什么来运行我的 Django 应用程序测试。

【问题讨论】:

    标签: python django unit-testing setuptools tox


    【解决方案1】:

    在你的setup.py:

    test_suite = "test_project.runtests.runtests",
    

    然后在你的项目中:

    #This file mainly exists to allow python setup.py test to work.
    import os, sys
    os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'
    test_dir = os.path.dirname(__file__)
    sys.path.insert(0, test_dir)
    
    from django.test.utils import get_runner
    from django.conf import settings
    
    def runtests():
        test_runner = get_runner(settings)
        failures = test_runner([], verbosity=1, interactive=True)
        sys.exit(failures)
    
    if __name__ == '__main__':
        runtests()
    

    this tutorial by Eric Holscher.

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 2015-07-04
    • 1970-01-01
    相关资源
    最近更新 更多