【问题标题】:How to add dictionary as an argument to unit-test function如何将字典作为参数添加到单元测试函数
【发布时间】:2019-01-01 19:47:53
【问题描述】:

很难解释。我正在尝试将此字典传递给 final.html 页面,但是当我运行测试时,它会显示“None:None”,就像它从未从高分字典中获取数据一样:

  class FlaskTestCase(unittest.TestCase):

     highscore = {1:2}

     def test_initial_word(self):
        with app.app_context():
             response = self.app.get("/final", data = dict(self.highscore , user = "test", score = 12)) 
             self.assertIn("quick and easy game", str(response.data))

当我尝试仅使用变量的其他测试时,一切正常:

 def test_initial_word(self):#Check if game.html has been created
        with app.app_context():
            response = self.app.get("/rules", data = dict(user = "test", score = 12)) 
            self.assertIn("test", str(response.data))

我应该如何正确地将字典添加到测试中?

【问题讨论】:

    标签: python flask python-unittest


    【解决方案1】:

    self.highscore 未分配给键名。你的意思是:

    response = self.app.get("/final", data=dict(highscore=self.highscore, user="test", score=12))

    【讨论】:

      猜你喜欢
      • 2019-09-14
      • 2017-08-14
      • 2020-01-06
      • 1970-01-01
      • 2018-09-14
      • 2017-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多