社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  pycharm

在Python IDE PyCharm中Unittest失败

mircead • 6 年前 • 2848 次点击  

我试着用Python做一个简单的unittest,但是我不知道为什么测试失败了。 我做了三份文件:

  • name_函数.py 其中我有一个函数接收两个参数( 名字,姓氏 )并返回连接的名称。
        def get_formatted_name(first, last):
            full_name = first + ' ' + last
            return full_name.title()
  • 名称.py 要求用户输入名字和姓氏,或 放弃。在那之后 获取格式化的名称 调用并打印连接的名称。
        from name_function import get_formatted_name

        print("\n Enter 'q' at any time to quit.")
        while True:
            first = input("\n Please give me a first name : ")
            if first == 'q':
                break
            last = input("\n Please give me a second name : ")
            if last == 'q':
                break

        formatted_name = get_formatted_name(first, last)
        print("\n\t Neatly formatted name : " + formatted_name + '.')   
  • test_name_function.py测试名称 测试功能的地方。
        import unittest  
        from name_function import get_formatted_name  

        class NamesTestCase(unittest.TestCase):  
            def test_first_last_name(self):  
                formatted_name = get_formatted_name('Clint', 'Eastwood')  
                self.assertEqual(formatted_name, 'Clint Eastwood')  

        unittest.main()  
  • 在这个窗口,我跑 命令 命令(请参见附加 捕获1 ).
  • 命令 我运行命令(参见附件 捕获2 捕获3 ).
  • 我不明白我的错误在哪里?在Capture_3中,查看我运行测试时获得的信息。
  • 我使用Python 3.7.2,我使用的IDE Python是PyCharm。

Capture_1 Capture_2 Capture_3

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52008
文章 [ 3 ]  |  最新文章 6 年前