我正在尝试使用来自unittest.mock的assert_used_once_with https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_ Called_once_with
但我想检查是否已通过正确的属性传递了两个对象实例。
所以在类中我重写了__eq__func:
def __eq__(self, other):
return (
self.id == other.id
and self.users == other.users
)
Run Code Online (Sandbox Code Playgroud)
在我这样使用的代码中
mock_add_user.assert_called_once_with(context_fix, expected_user_obj1, expected_user_obj2, users)
Run Code Online (Sandbox Code Playgroud)
但我不断收到错误,并且测试人员不断比较实例的 repr,如下所示
<app.domain.model.load_md.Load object at 0x10cb7d7d0>
Run Code Online (Sandbox Code Playgroud)
<app.domain.model.load_md.Load object at 0x10cb7d7d0>
Run Code Online (Sandbox Code Playgroud)
我确实需要一种方法来断言对象的实例是否已作为填充了正确属性的函数的参数传递。
数据库:postgres
\nORM:类型
\n框架:express.js
\n我有一个表,其中一个名为 name 的字段projects是一个字符串数组。类型"varchar"在迁移中设置为 ,装饰器设置为"simple-array"。
在我的获取路线中,如果我收到查询,?project=name_of_the_project它应该尝试在简单数组中查找项目。
对于搜索我的获取路线是这样的:
\nstudentsRouter.get("/", async (request, response) => {\n const { project } = request.query;\n const studentRepository = getCustomRepository(StudentRepository);\n const students = project\n ? await studentRepository\n .createQueryBuilder("students")\n .where(":project = ANY (students.projects)", { project: project })\n .getMany()\n : await studentRepository.find();\n // const students = await studentRepository.find();\n return response.json(students);\n}); \nRun Code Online (Sandbox Code Playgroud)\n问题是 I\xc2\xb4m 收到错误,指出右侧应该是一个数组。
\n(node:38971) UnhandledPromiseRejectionWarning: QueryFailedError: op …Run Code Online (Sandbox Code Playgroud)