Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the `python setup.py test` syntax to work?

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()
like image 247
A T Avatar asked Jan 21 '14 06:01

A T


People also ask

How do I run python setup py?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.

How do I run a test in setup py?

You can just specify test_suite="tests", and it will pick up everything recursively. Note that each nested directory will need to have an __init__.py file in it. You need to do from setuptools import setup instead of from distutils. core import setup for this option to exist.

How does pip use setup py?

As a first step, pip needs to get metadata about a package (name, version, dependencies, and more). It collects this by calling setup.py egg_info . The egg_info command generates the metadata for the package, which pip can then consume and proceed to gather all the dependencies of the package.


1 Answers

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

from setuptools import setup
like image 200
tuomur Avatar answered Sep 20 '22 07:09

tuomur