如何对嵌套函数进行单元测试? [英] How do you unit test a nested function?

查看:321
本文介绍了如何对嵌套函数进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下示例中,如何对嵌套函数f1()进行单元测试?

How would you unit test the nested function f1() in the following example?

def f():
    def f1():
       return 1
    return 2

还是应该嵌套需要测试的功能?

Or should functions that need testing not be nested?

推荐答案

There is a similar question in this link. But short answer: you can't access an inner function from an outer element.

出于测试目的,也许替代方法是更改​​私有外部函数的内部函数?

For testing purposes, maybe an alternative would be to change the inner function for a private outer one?

这篇关于如何对嵌套函数进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆