关于python测试代码在jupyter notebook出错
关于python测试代码出错
新手在看《python编程从入门到实践》这本书时,在jupyter notebook运行代码报错
相关代码
name_function.py:
def name_function_name(first,last): """Generate a neatly formatted full name"""
full_name=first+' '+last
return full_name.title()
import unittestfrom name_function import name_function_name
class NameTestCase(unittest.TestCase):
"""测试name_fucntion"""
def test_first_last_name(self):
formatted_name=name_function_name('janis','joplin')
self.assertEqual(formatted_name,'Janis Joplin')
unittest.main()
报错信息:
AttributeError: module '__main__' has no attribute 'C:\Users\lenovo\AppData\Roaming\jupyter\runtime\kernel-11844d9b-55f1-4e3a-b4c9-fb59461d0462'----------------------------------------------------------------------
Ran 1 test in 0.001s
FAILED (errors=1)
An exception has occurred, use %tb to see the full traceback.
SystemExit: True
E:\Anaconda\lib\site-packages\IPython\core\interactiveshell.py:3426: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)
请问如何解决啊
回答:
试试这样
if __name__ == '__main__': unittest.main(argv=['first-arg-is-ignored'],exit=False)
以上是 关于python测试代码在jupyter notebook出错 的全部内容, 来源链接: utcz.com/p/938359.html