Python - 依赖于先前函数结果的单元测试函数(链式函数)
Python - Unit testing functions that are dependant on previous functions outcome (Chained functions)
我有三个相互依赖的 python functions
:f()、g() 和 h(),例如:
g()
取决于f()
的结果。
h()
取决于 g()
. 的结果
def f():
...
def g():
f()
...
def h():
g()
...
为了unit test
这些功能我正在使用py.test
。在我尝试进行单元测试的过程中,我观察到一些冗余:
def test_f():
assert f()
def test_g():
f()
assert g()
def test_h():
g()
assert h()
在这种特殊情况下,我应该如何设计 Unit Tests
?
我不确定我是否理解正确,但如果我理解正确,那么你可以
def test_functions():
assert f()
assert g()
assert h()
我有三个相互依赖的 python functions
:f()、g() 和 h(),例如:
g()
取决于f()
的结果。h()
取决于g()
. 的结果
def f():
...
def g():
f()
...
def h():
g()
...
为了unit test
这些功能我正在使用py.test
。在我尝试进行单元测试的过程中,我观察到一些冗余:
def test_f():
assert f()
def test_g():
f()
assert g()
def test_h():
g()
assert h()
在这种特殊情况下,我应该如何设计 Unit Tests
?
我不确定我是否理解正确,但如果我理解正确,那么你可以
def test_functions():
assert f()
assert g()
assert h()