Question

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()
Was it helpful?

Solution

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

from setuptools import setup
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top