Python 工作服未测试 "if name == __main__"
Python coveralls not testing "if name == __main__"
我有一个文件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()
这 运行s 在 coveralls 中,但从未到达最后一行。 (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__
子句。删掉就行了。
我有一个文件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()
这 运行s 在 coveralls 中,但从未到达最后一行。 (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__
子句。删掉就行了。