Python doctests / sphinx:风格指南,如何使用它们并拥有可读的代码?
我喜欢 doctests,它是我使用的唯一测试框架,因为它编写起来非常快,而且因为与 sphinx 一起使用,它几乎不费吹灰之力就能制作出如此出色的文档......
但是,很多时候,我最终会做类似的事情this :
"""
Descriptions
=============
bla bla bla ...
>>> test
1
bla bla bla + tests tests tests * 200 lines = poor readability of the actual code
"""
我的意思是,我将所有带有文档说明的测试放在模块的顶部,因此您必须愚蠢地滚动才能找到实际的代码,这非常难看(在我看来)。但是,我认为文档测试仍应保留在模块中,因为您应该能够在阅读源代码时阅读它们。 那么我的问题来了:sphinx/doctests爱好者,你们如何组织你们的doctests,比如代码可读性不受影响?是否有针对 doctests、sphinx 的风格指南?对于 sphinx 的文档字符串,您使用 google 或 sphinx style-guide 还是其他什么?
I love doctests, it is the only testing framwork I use, because it is so quick to write, and because used with sphinx it makes such great documentations with almost no effort...
However, very often, I end-up doing things like this :
"""
Descriptions
=============
bla bla bla ...
>>> test
1
bla bla bla + tests tests tests * 200 lines = poor readability of the actual code
"""
What I mean is that I put all my tests with documentation explanations on the top of the module, so you have to scroll stupidly to find the actual code, and this is quite ugly (in my opinion). However, I think that the doctests should still stay in the module, because you should be able to read them while reading the source code.
So here comes my question : sphinx/doctests lovers, how do you organize your doctests, such as the code readability doesn't suffer ? Is there a style guide for doctests, for sphinx ? For docstring with sphinx, do you use google or sphinx style-guide or something else ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为文档测试有两种。
与普通文档不同,文档测试的美妙之处在于,即使它们不在同一屏幕中,您也可以确保它们与代码保持同步。阅读代码时,您希望看到代码,也许带有一些描述性文本。在阅读教程时,您不想只看到代码而是示例。
I think there are two sorts of doctest.
Unlike ordinary documentation, the beauty of doctesting is that you can be sure they are going to stay in sync with the code even if they aren't in the same screen. When reading the code you want to see code, perhaps with a little descriptive text. When reading a tutorial you don't want to see the code just the examples.