首页 > 解决方案 > python mocks在'function'中找不到引用'assert_call_with'

问题描述

我在 python 中有这些简单的函数:

一个.py

def fn1(a, b):
    return a + b


def fn1_reverted(a, b):
    return fn1(b, a)

它的测试:

a_test.py

import a

def test_fn1():
    assert a.fn1('a', 'b') == 'ab'


def test_fn1_reverted(mocker):
    mocker.patch.object(a, 'fn1')
    a.fn1_reverted('a', 'b')
    a.fn1.assert_called_with('b', 'a')

我收到 pycharm 的警告: Cannot find reference 'assert_called_with' in 'function'

难道我做错了什么?

这是断言使用特定参数调用内部函数的正确方法吗?

标签: pythonmockingpycharmpytest

解决方案


推荐阅读