How to run unittest discover from “python setup.py test”?

前端 未结 7 2056
不知归路
不知归路 2020-12-12 19:39

I\'m trying to figure out how to get python setup.py test to run the equivalent of python -m unittest discover. I don\'t want to use a run_tests.p

相关标签:
7条回答
  • 2020-12-12 20:16

    Python's standard library unittest module supports discovery (in Python 2.7 and later, and Python 3.2 and later). If you can assume those minimum versions, then you can just add the discover command line argument to the unittest command.

    Only a small tweak is needed to setup.py:

    import setuptools.command.test
    from setuptools import (find_packages, setup)
    
    class TestCommand(setuptools.command.test.test):
        """ Setuptools test command explicitly using test discovery. """
    
        def _test_args(self):
            yield 'discover'
            for arg in super(TestCommand, self)._test_args():
                yield arg
    
    setup(
        ...
        cmdclass={
            'test': TestCommand,
        },
    )
    
    0 讨论(0)
提交回复
热议问题