Alex Rivera | Logout

Can I restrict nose coverage output to directory (rather than package)?

Asked 2009-05-12T22:06:28.977
20

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?"

Edit
Report

2 Answers

3

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.

answered 2009-05-12T23:10:06.953
2

I would do this:

nosetests --with-coverage --cover-package=foo,bar tests/*

I prefer this solution to the others suggested; it's simple yet you are explicit about which packages you wish to have coverage for. Nadia's answer involves a lot more redundant typing, Stuart's answer uses sed and still creates a package by invoking touch __init__.py, and --cover-package=. doesn't work for me.

answered 2013-04-19T09:54:24.143

Your Answer