带有文件io的python Unittest依赖关系
我有两个函数
def complex_func():
# generate result.csv
def post_process_func(csv_fname):
# do something with result.csv
,我想为每个功能建立一个Unitest
def test_complex_func():
complex_func()
assert result.csv exists
assert contents of result.csv is correct
,但是要测试POST_PROCESS_FUNC
我需要result.csv,所以我需要调用confect> confects_func()
,并且它是原因的。两个Unitests之间的依赖性问题。
我搜索并找到了模拟
或补丁
,但是这些对于覆盖函数或对象的返回值而不是文件io很有用。
以Python的方式将这两种Undests分开的最佳方法是什么?
I have two functions
def complex_func():
# generate result.csv
def post_process_func(csv_fname):
# do something with result.csv
and I want to make a unittest for each function
def test_complex_func():
complex_func()
assert result.csv exists
assert contents of result.csv is correct
However, to test post_process_func
I need a result.csv so I need to call complex_func()
and it causes dependency issue between two unittests.
I searched and found mock
or patch
but those are useful to override the return value of function or object, not the file IO.
What's the best way to separate these two unittests in python way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论