15

How do I get python setup.py test to work? - Current output:

$ 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/tests/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()
A T
  • 13,008
  • 21
  • 97
  • 158

1 Answers1

17

test_suite is a feature of setuptools. Replace distutils with it:

from setuptools import setup
tuomur
  • 6,888
  • 34
  • 37
  • 2
    Your `test_suite` should probably contain `proj_name.tests`, as the documentation suggests. – tuomur Jan 21 '14 at 06:54
  • See also https://stackoverflow.com/questions/20941880/how-to-run-test-suite-in-python-setup-py – Dacav Nov 12 '15 at 14:13