我有一个文件test_gather.py
import gather
class TestGather(unittest.TestCase):
def test_01_gather(self):
self.assertEqual(len(gather.lookup_terms) > 2, True)
if __name__ == '__main__':
unittest.main()
这在工作服中运行,但永远不会到达最后一行。 (https://coveralls.io/builds/3180464/source?filename=tests%2Ftest_gather.py)
我的travis.yaml
如下:
language: python
python:
- "3.4"
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
install:
- pip install .
- pip install coverage
- pip install nose coverage
- pip install coveralls
script:
- python setup.py nosetests --with-coverage --cover-package pypiview
- coverage run --source=rawdata setup.py test
- nosetests --with-coverage
after_success:
coveralls
如何配置它以确保所有 tests/test_*.py
文件都运行,以便最后一行也被执行?
最佳答案
您正在使用测试发现来查找并运行测试。您根本不需要 if __name__
子句。删除它即可。
关于Python 工作服未测试 "if name == __main__",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31910748/