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

前端 未结 7 2078
不知归路
不知归路 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:09

    This won't remove run_tests.py, but will make it work with setuptools. Add:

    class Loader(unittest.TestLoader):
        def loadTestsFromNames(self, names, _=None):
            return self.discover(names[0])
    

    Then in setup.py: (I assume you're doing something like setup(**config))

    config = {
        ...
        'test_loader': 'run_tests:Loader',
        'test_suite': '.', # your start_dir for discover()
    }
    

    The only downside I see is it's bending the semantics of loadTestsFromNames, but the setuptools test command is the only consumer, and calls it in a specified way.

提交回复
热议问题