[TIP] Testing specific code

Kumar McMillan kumar.mcmillan at gmail.com
Thu Sep 3 11:33:43 PDT 2009

> On Tue, Sep 01, 2009 at 03:46:02PM -0600, Matt Harrison wrote:
> -> [...] As an idea to help deal with that and
> -> to help focus coverage attention on specific code points, I thought of
> -> an idea.  (I'm assuming others here have probably thought of it before
> -> to).  What I'd like to do is have a (emacs) command that says 'run
> -> tests for this function/method'.  Then something
> -> (nose??/plugin??/emacs??) goes and finds tests that invoke that method
> -> and only runs those tests and reports coverage for them.

yea, this would be really slick.  Holger had a good idea for this
which is pretty straight forward and easier than grepping.  You just
add a list of test files to each code module.  I.E.

   # content of: mymodule.py

   # relative paths
   __testfiles__ = ['test/test_unittest.py', 'test/test_functional.py']

It's not as granular as what you're talking about but might be good
enough for figuring out what tests to run given a function/method.

To get more precise about it, yeah, you'd probably need some kind of
trace function that kept track of what functions were executed during
each test.

> -> A naive
> -> implementation would be a simple regex match for the function name and
> -> then look to see if it resides in a test.  That way you can edit your
> -> codes and your tests and quickly retrieve relevant coverage
> -> information.  Does this make sense?
> ->
> -> So before I go off and implement this I thought I'd ask if it already
> -> exists.  I can't find it.  Also feedback is good.   Is there a better
> -> method/workflow?  I'd imagine other's might find such functionality
> -> useful even without coverage information.  ie when you are looking
> -> at/developing tests for code that is new to you.  I would think a nose
> -> plugin would work best...

More information about the testing-in-python mailing list