hhbcarl hhbcarl - 1 year ago 147
Python Question

Pragmas in python

I'm reading bottle.py source code. It's a web framework, with only 3000+ lines python code. So cool.

I found some code like this:

class ServerAdapter(object):
quiet = False
def __init__(self, host='', port=8080, **config):
self.options = config
self.host = host
self.port = int(port)

def run(self, handler): # pragma: no cover

What does the
# pragma: no cover
mean? I can't find any introduce about the
syntax in the python documentations.

Answer Source

It is apparenly related to the 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.

That exact # pragma: no cover is the hint that the part of code should be ignored by the tool -- see Excluding code from coverage .

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download