views:

278

answers:

2

My SUT looks like:

foo.py
bar.py
tests/__init__.py [empty]
tests/foo_tests.py
tests/bar_tests.py
tests/integration/__init__.py [empty]
tests/integration/foo_tests.py
tests/integration/bar_tests.py

When I run nosetests --with-coverage, I get details for all sorts of modules that I'd rather ignore. But I can't use the --cover-package=PACKAGE option because foo.py & bar.py are not in a package. (See the thread after http://lists.idyll.org/pipermail/testing-in-python/2008-November/001091.html for my reasons for not putting them in a package.)

Can I restrict coverage output to just foo.py & bar.py?

Update - Assuming that there isn't a better answer than Nadia's below, I've asked a follow up question: "How do I write some (bash) shell script to convert all matching filenames in directory to command-line options?"

+3  A: 

You can use it like this:

--cover-package=foo --cover-package=bar

I had a quick look at nose source code to confirm: This is the line

    if options.cover_packages:
        for pkgs in [tolist(x) for x in options.cover_packages]:
Nadia Alramli
I'm impressed that you looked at the source. (I should have thought of that.)But it shows I need to use "--cover-package=foo --cover-package=bar". If you modify your answer I'll accept it (and vote it up).
Daryl Spitzer
Thanks for the note. I fixed the answer. I've never used nose before. But I thought I'd give the question a try since no one else answered.
Nadia Alramli
Thanks Nadia. You still need to remove the ".py" extensions, since the arguments are the package names, not the file names.
Daryl Spitzer
Opps, sorry about the mistakes. Fixed :)
Nadia Alramli
+1  A: 

If you use coverage:py 3.0, then code in the Python directory is ignored by default, including the standard library and all installed packages.

Ned Batchelder