问题描述
请我解释一下在使用unittest.TestCase时如何无法在jupyter中运行此代码,但是该功能可以完全独立运行。
这是我的功能:
def get_formatted_name(first,last):
"""Generate a neatly formatted full name"""
full_name = first + ' ' + last
return full_name.title()
print("Enter 'quit' at any point to quit. ")
while True:
first = input("\nPlease enter your first name: ")
if first == 'quit':
break
last = input("Please enter your last name: ")
if last == 'quit':
break
formatted_name = get_formatted_name(first,last)
print("\tNeatly formatted name: " + formatted_name + '.')
现在是单元测试用例:
import unittest
from get_names import get_formatted_name
# second step
class NamesTestCase(unittest.TestCase):
"""Tests for 'get_names.py'."""
def test_first_last_name(self):
"""Do names like Kelvin Nnabugwu work?"""
formatted_name = get_formatted_name('kelvin','john')
self.assertEqual(formatted_name,'Kelvin John')
unittest.main()
这是错误消息:
E
======================================================================
ERROR: C:\Users\Nnabugwu kevin\AppData\Roaming\jupyter\runtime\kernel-1b2f6cd8-cd44-438c-ad1f-f775cd1625a2 (unittest.loader._FailedTest)
----------------------------------------------------------------------
AttributeError: module '__main__' has no attribute 'C:\Users\Nnabugwu kevin\AppData\Roaming\jupyter\runtime\kernel-1b2f6cd8-cd44-438c-ad1f-f775cd1625a2'
----------------------------------------------------------------------
Ran 1 test in 0.001s
Failed (errors=1)
An exception has occurred,use %tb to see the full traceback.
SystemExit: True
D:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py:3339: UserWarning: To exit: use 'exit','quit',or Ctrl-D.
warn("To exit: use 'exit',or Ctrl-D.",stacklevel=1)
请我解释一下这是怎么工作的
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)