0
我是一个单元测试函数,它使用由其他函数声明的变量。Python嘲笑在另一个函数中声明的全局变量
def first_fun():
global file_path
file_path = get_file_path()
.
.
def second_fun():
with open(file_path, "r") as flz:
.
.
如何在测试second_fun()时模拟file_path? 我试过但不起作用。
@patch.object(source_module, 'file_path')
def test_second_fun(self):
source_module.second_fun()
我不断获取......没有属性 'FILE_PATH'
最好的解决方案不是使用'global',它被许多开发人员视为反模式。 –