我正在阅读 bottle.py 源代码。它是一个 Web 框架,只有 3000 多行 Python 代码。太酷了。
我发现了一些这样的代码:
class ServerAdapter(object):
quiet = False
def __init__(self, host='127.0.0.1', port=8080, **config):
self.options = config
self.host = host
self.port = int(port)
def run(self, handler): # pragma: no cover
pass
...
# pragma: no cover
是什么意思?我在 python 文档中找不到任何关于 pragma
语法的介绍。
最佳答案
显然与 coverage.py 有关:
Coverage.py is a tool for measuring code coverage of Python programs. It monitors your program, noting which parts of the code have been executed, then analyzes the source to identify code that could have been executed but was not.
确切的 # pragma: no cover
提示该工具应忽略该部分代码 -- 参见 Excluding code from coverage .
关于python - python中的编译指示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11992448/