[TIP] coverage.py vs QGIS

Skip Montanaro skip.montanaro at gmail.com
Wed Apr 15 05:21:56 PDT 2020

> QGIS is a C++/Qt5 app at the moment. At some point in the past, Python
> scripting capability, a Python console inside the app and a Python
> plugin system were added, see (1). The QGIS-API-to-Python bridge is
> based on SIP (2). Python itself is linked into the app through
> `libpython`, see (3). Therefore there is no Python command that I can
> substitute with coverage.

I would try creating a .coveragerc file and running your program with
COVERAGE_PROCESS_START set to refer to it. See if that provokes some
meaningful output.

> import os
> import atexit
> from coverage import Coverage
> _cov = Coverage(source = os.path.dirname(__file__))
> _cov.start()
> atexit.register(_cov.stop)
> ```
> The use of `atexit` did not work at all, ...

As in didn't produce a call to _cov.stop? I don't see any mention of
running coverage.py when Python is embedded, but I do see an open issue
about it. What if you try something more basic. Skip the coverage stuff
altogether, but register a visible exit handler:

atexit.register(print, "goodbye world")
If that doesn't work, maybe someone else has an idea how to provoke
coverage output at intervals during the run. Perhaps you could schedule
calls to _cov.save at intervals during the run from a plugin.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20200415/9d4a2024/attachment.html>

More information about the testing-in-python mailing list