Python Crash Course,测试您的代码示例

时间:2017-09-28 18:28:24

标签: python

这是为了测试班级;但是,我收到错误,我不知道如何解决它。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
     $('#textarea').keyup(function() {
         $('#dateD').html($('#div.timing').html());
     });
 });
</script>

<input type="hidden" id="dateD" value="" name="time1" >

这是正在测试的课程。

import unittest
from name_function import get_formatted_name

class NamesTestCase(unittest.TestCase):
  """Tests for 'name_function.py'"""

  def test_first_last_name(self):
    """Do names like 'Mark James' work?"""
    formatted_name = get_formatted_name('mark','James')
    self.assertEqual(formatted_name,'Mark James')

unittest.main()

我得到的错误是:

def get_formatted_name(first, last):
  """This is where the name is formatted correctly"""
  full_name = first + " " + last
  return full_name.title()

任何人都有线索?

1 个答案:

答案 0 :(得分:0)

我相信你需要添加if&#39; name &#39; ==&#39; 主要&#39;:     unittest.main()代码。

以下代码应该修复错误 -

import unittest
from name_function import get_formatted_name

class NamesTestCase(unittest.TestCase):
    """Tests for 'name_function.py'"""

  def test_first_last_name(self):
      """Do names like 'Mark James' work?"""
      formatted_name = get_formatted_name('mark','James')
      self.assertEqual(formatted_name,'Mark James')
if '__name__' == '__main__':
    unittest.main()