单位测试不起作用

时间:2017-07-29 03:57:22

标签: python python-unittest

我无法弄清楚为什么没有运行测试: python tests/quick_tests.py和python unittest。

以下是文件的内容:

import sys
import os
from App import app
import unittest
from App.helpers import *
from werkzeug.security import generate_password_hash
import requests
import pdb
import pickle
from App.models import *
import re
from httmock import all_requests, response, HTTMock, urlmatch
from mock_apis import *


class AppTestCase(unittest.TestCase):
    def setUp(self):
        self.app = app.test_client()
        app.config['WTF_CSRF_ENABLED'] = False


    def tearDown(self):
        del self.app

    def testhome(self):
        with app.app_context():
            r = self.app.get('/')
            self.assertEqual(r.status_code, 200)


if __name__ == '__main__':
    unittest.main()

刚刚结果:

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

请指导我。任何帮助表示赞赏!

2 个答案:

答案 0 :(得分:0)

试试这个:

def main(): 
   '''Run the unit test ''' 
   tester = unittest.main(exit=False)     
   sys.exit(0 if tester.result.wasSuccessful() else -1)

if __name__ == '__main__': 
   main()



__all__ = [ 
   'AppTestCase'
]

答案 1 :(得分:0)

隐藏我App中的文件,并以二进制搜索方式对它们进行评论,看看单元测试在哪里开始破解,我发现删除单个import ipdb可以解决问题。我不知道从这个中得出什么结论:单元测试与ipdb不一致。希望这篇文章能够拯救其他民族。未来的时间。

相关问题