运行单元测试用例:python -m unittest discover
覆盖率:coverage run -m unittest discover
coverage report
import unittest from app import app from app.models import Todo class TodoTestCase(unittest.TestCase): def setUp(self): self.app = app.test_client() def tearDown(self): todos = Todo.objects.all() for todo in todos: todo.delete() def test_index(self): rv = self.app.get('/') assert "Todo" in rv.data