pytestest ting主
考虑一个简单的程序,例如:
- main.py
- reader.py
- test_reader.py,
让我们假设reader.py是由test_reader.py进行的100%覆盖范围测试。
测试一个看起来像这样的主的测试将如何进行:
from Reader import myClass
import argparse
if __name__ == '__main__':
# argparsing eluded
parser = argparse.ArgumentParser(description='my descrition')
parser.add_argument('myarg1', nargs='?',
default = 1)
parser.add_argument('myarg2', nargs='?',
default = 1)
args = parser.parse_args()
myClass(args.myarg1, args.myarg2)
如何处理? 我的第一个论点是,该算法是如此简单,因此不需要测试。但是,我不确定您是否需要测试它是否有原因。
我知道嘲笑argparse需要一些嘲笑,如这个问题所述: pytest with agrparse:如何提示用户进行确认? 但是,实际嘲笑简单的东西(所有实际操作都在其他模块中)是否值得努力?
Considering a simple program like:
- main.py
- Reader.py
- test_Reader.py
Let's assume Reader.py is 100% coverage-tested by test_Reader.py.
How would one go with testing a main that would look like this:
from Reader import myClass
import argparse
if __name__ == '__main__':
# argparsing eluded
parser = argparse.ArgumentParser(description='my descrition')
parser.add_argument('myarg1', nargs='?',
default = 1)
parser.add_argument('myarg2', nargs='?',
default = 1)
args = parser.parse_args()
myClass(args.myarg1, args.myarg2)
How would one go with that?
My first argument was that the algorithm is so simple it does not require to be tested. However, I am not sure if there is a reason why you would need to test that.
I know mocking argparse requires some mocking as explained in this question : Pytest with argparse: how to test user is prompted for confirmation?
But is it worth the effort to actually mock something that simple (all the actual operations are in the other module)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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