time per test?

1054 views
Skip to first unread message

sk...@pobox.com

unread,
Aug 16, 2010, 1:25:43 PM8/16/10
to nose-...@googlegroups.com
Is there some way to get the nosetests command to display the time it takes
to run individual tests? I'm running nose 0.11.3.

I have two versions of a C library, one with a ctypes wrapper and one with a
Boost.Python wrapper. The test cases for the ctypes wrapped version run
about 5x faster than the Boost.Python wrapped version overall. I except the
ctypes version to be faster, but not by that much. I'd like to focus my
attention primarily on those test cases with the largest differences to try
and figure out what's going on. Upgrading to a newer version is no problem.

Thanks,

--
Skip Montanaro - sk...@pobox.com - http://www.smontanaro.net/

Kumar McMillan

unread,
Aug 16, 2010, 2:23:59 PM8/16/10
to nose-...@googlegroups.com
On Mon, Aug 16, 2010 at 12:25 PM, <sk...@pobox.com> wrote:
> Is there some way to get the nosetests command to display the time it takes
> to run individual tests?  I'm running nose 0.11.3.
>
> I have two versions of a C library, one with a ctypes wrapper and one with a
> Boost.Python wrapper.  The test cases for the ctypes wrapped version run
> about 5x faster than the Boost.Python wrapped version overall.  I except the
> ctypes version to be faster, but not by that much.  I'd like to focus my
> attention primarily on those test cases with the largest differences to try
> and figure out what's going on.  Upgrading to a newer version is no problem.

You could use the builtin --with-profile plugin to get stats per test.
Otherwise you could write a simple plugin that started a timer in
startTest() and finished it in addError(), addSuccess(), or
addFailure()


>
> Thanks,
>
> --
> Skip Montanaro - sk...@pobox.com - http://www.smontanaro.net/
>

> --
> You received this message because you are subscribed to the Google Groups "nose-users" group.
> To post to this group, send email to nose-...@googlegroups.com.
> To unsubscribe from this group, send email to nose-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nose-users?hl=en.
>
>

sk...@pobox.com

unread,
Aug 16, 2010, 3:15:19 PM8/16/10
to nose-...@googlegroups.com

Kumar> You could use the builtin --with-profile plugin to get stats per
Kumar> test. Otherwise you could write a simple plugin that started a
Kumar> timer in startTest() and finished it in addError(), addSuccess(),
Kumar> or addFailure()

Thanks. I guess maybe I ought to figure out how to write a "simple plugin",
huh?

Skip

Kumar McMillan

unread,
Aug 16, 2010, 3:36:40 PM8/16/10
to nose-...@googlegroups.com

Xunit already does exactly this to report time between tests in Hudson
metrics. You could copy its Plugin class:
http://bitbucket.org/jpellerin/nose/src/tip/nose/plugins/xunit.py

For some reason it uses %d to format the time which cuts off decimals.
I'm not sure if that's a bug or not. Hmm.

btw, here's how to activate custom plugins for one-time use:
http://somethingaboutorange.com/mrl/projects/nose/0.11.2/plugins/writing.html#registering-a-plugin-without-setuptools

>
> Skip

sk...@pobox.com

unread,
Aug 16, 2010, 5:53:52 PM8/16/10
to nose-...@googlegroups.com

Kumar> Xunit already does exactly this to report time between tests in
Kumar> Hudson metrics. You could copy its Plugin class:
Kumar> http://bitbucket.org/jpellerin/nose/src/tip/nose/plugins/xunit.py

Thanks. Is there a "hello world" for plugins though? I haven't the
slightest idea how Nose would even find a plugin, let alone run it. I
Googled for "nose plugins" and landed here (first hit):

http://somethingaboutorange.com/mrl/projects/nose/doc/plugin_interface.html

but that doesn't seem to tell me how to install a plugin so Nose can find
it. (It might, but I could well be missing it. For example, neither
"install" nor "search" appear on that page. I'd sort of expect one of them
to turn up on a page about writing plugins.)

I then tried Googling for "nose plugins tutorial" which yielded this:

http://python-nose.googlecode.com/svn/wiki/WritingPlugins.wiki

which looks like it has more of what I'm after ("For nose to find a
plugin..."), but it bothers me that this page doesn't seem to be current. I
can't find it in the Nose wiki:

http://code.google.com/p/python-nose/w/list

Kumar> btw, here's how to activate custom plugins for one-time use:
Kumar> http://somethingaboutorange.com/mrl/projects/nose/0.11.2/plugins/writing.html#registering-a-plugin-without-setuptools

Thanks. That does help. Is somethingaboutorange.com the official Nose
project site or is it a Google Code project (which seems to be utterly
devoid of any documentation)? And what is nose-plugins.jottit.com?

It's all a bit confusing. Documentation-wise, anyway.

Skip

Kumar McMillan

unread,
Aug 16, 2010, 6:25:09 PM8/16/10
to nose-...@googlegroups.com
Thanks for all the feedback from your perspective. I suppose it would
help if we retired some of those old wiki pages. The official
documentation starts here:
http://somethingaboutorange.com/mrl/projects/nose/

If you click on Developing With Nose then after a few clicks you might
arrive at Write Plugins:
http://somethingaboutorange.com/mrl/projects/nose/0.11.2/plugins/writing.html

That has some recipes but I agree it could use a simple Hello World
plugin before the recipes section.

http://nose-plugins.jottit.com/ is some attempt at a "plugin
repository" maintained by me.

MikiTebeka

unread,
Aug 17, 2010, 9:48:09 PM8/17/10
to nose-users
I used the --with-xunit and the following code to process
nosetests.xml

from xml.etree.cElementTree import parse
from operator import itemgetter

elems = parse(open("nosetests.xml")).getiterator("testcase")
tests = sorted(((e.get("name"), int(e.get("time"))) for e in elems),
key=itemgetter(1), reverse=1)

for test in (test for test in tests if test[1]):
print "%s: %s sec" % test


HTH,
--
Miki
> Skip Montanaro - s...@pobox.com -http://www.smontanaro.net/
Reply all
Reply to author
Forward
0 new messages