让`python setup.py test`语法工作?

时间:2014-01-21 06:05:52

标签: python unit-testing distutils setup.py python-unittest

如何让python setup.py test工作? - 当前输出:

$ python setup.py test  # also tried: `python setup.py tests`
/usr/lib/python2.7/distutils/dist.py:267: \
                           UserWarning: Unknown distribution option: 'test_suite'
  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'

PROJ_NAME / setup.py

from distutils.core import setup

if __name__ == '__main__':
    setup(name='foo', version='0.1', package_dir={'foo': 'utils'},
          test_suite='tests')

PROJ_NAME /测试/ foo_test.py

from unittest import TestCase, main as unittest_main


class TestTests(TestCase):
    def setUp(self):
        pass

    def test_foo(self):
        self.assertTrue(True)
        self.assertFalse(False)


if __name__ == '__main__':
    unittest_main()

1 个答案:

答案 0 :(得分:14)

test_suitesetuptools的一项功能。用它替换distutils:

from setuptools import setup