Unit tests and coverage
ned at nedbatchelder.com
Sun Dec 29 15:07:34 CET 2013
On 12/28/13 11:21 PM, Joseph L. Casale wrote:
> I have a script that accepts cmdline arguments and receives input via stdin.
> I have a unit test for it that uses Popen to setup an environment, pass the args
> and provide the stdin.
> Problem is obviously this does nothing for providing coverage. Given the above
> specifics, anyone know of a way to work around this?
It sounds like you may have already found the coverage.py docs on
measuring subprocesses. Another approach is to refactor your code so
that the bulk of it can be invoked without a subprocess, then test that
code with simple function calls. Those tests will be easy to measure
with coverage.py, and by the way, they'll run much faster and be easier
Ned Batchelder, http://nedbatchelder.com
More information about the Python-list