Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 模拟Peewe类不会返回值_Python_Unit Testing_Mocking_Mockito_Peewee - Fatal编程技术网

Python 模拟Peewe类不会返回值

Python 模拟Peewe类不会返回值,python,unit-testing,mocking,mockito,peewee,Python,Unit Testing,Mocking,Mockito,Peewee,模拟peewe类以模拟类属性 models.py import peewe class A(): human = CharField() class B(): first = CharField() second = ForeignKeyField(B, related_name="addresses") test.py 从模拟导入补丁 def build_A_model(): var = models.A() var.human = "yes" d

模拟peewe类以模拟类属性

models.py

import peewe

class A():
    human = CharField()


class B():
    first = CharField()
    second = ForeignKeyField(B, related_name="addresses")
test.py 从模拟导入补丁

def build_A_model():
   var = models.A()
   var.human = "yes"

def build_B_model(A_fake_model):
   var1 = models.B()
   var1.first = "test"
   var1.second = A_fake_model
   return var1

@patch(models.A)
 class testing(unittest.TestCase):
     def test1(self, A_mock):
         A_fake_model = build_A_model()
         B_model = build_B_model(A_fake_model)
         expected = {
            "first": "test",
            "second": {
                "human": "yes"
            },
          }
         # some function to searlize B_model to json
         result = json_searlized_data
         self.assertEqual(expected, result)
任务:尝试模拟A_模型和B_模型以获得预期结果:

问题:Mock\u类返回一个神奇的Mock(),而不是返回一个值

错误:human:MagicMock name='xxxxx'id='139670936802896''


问题:如何返回模拟类的值\u模型?

您没有返回任何内容:

def build_A_model():
   var = models.A()
   var.human = "yes"
添加一个返回语句