我构建了一个Django应用程序并使用setuptools
创建了一个包。现在,我想做以下事情:
我想用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'
我想使用Tox来运行我的测试,但我不知道应该在command
属性中写什么来运行我的Django app测试。
答案 0 :(得分:3)
在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()