1

In python, I have a script called script.py and a subdirectory with the test

tests
    __init__.py
    test_set01.py
    test_set02.py

for check the untested functions in script.py I use this bash script

#!/bin/bash

for f in $(egrep "^def" script.py | sed "s/(/\t/" | awk '{print $2}' )
do
if [ "" = "$(grep $f tests/*.*)" ]
then
    echo $f
fi
done

exists a better way to find functions without test?

JuanPablo
  • 23,792
  • 39
  • 118
  • 164
  • Sure. [Get a list of all of the functions in your module](http://stackoverflow.com/questions/139180/listing-all-functions-in-a-python-module), then check your test modules. I'd like to know a little bit more about the way you're checking using that `grep` though. What do the contents of `script.py` and the modules in `tests` look like? I can give you a concrete answer if you help me out there. – 2rs2ts Feb 20 '14 at 13:50
  • 1
    Also, a little search for python test coverage yielded [this library called `coverage`](http://nedbatchelder.com/code/coverage/) which will probably get the job done too. – 2rs2ts Feb 20 '14 at 13:54

1 Answers1

0

There's several good projects which aims to detect what you would call "Code Coverage." That is, just how much of your code is covered by unit tests. And just like there are several projects, there's several different measures you can make to determine code coverage:

  1. Lines of Code
  2. Function points
  3. Logical paths

All of these can be gamed. However, any solution is probably better than just grepping like you've done.

Take a look at:

  1. Coveragepy.
  2. For Nose, look at cover.
  3. Also Figleaf (but I don't know how mature it is compared to Coverage.)
wheaties
  • 35,646
  • 15
  • 94
  • 131