[openstack-dev] [nova] fastest way to run individual tests ?

Mike Bayer mbayer at redhat.com
Thu Jul 10 15:58:55 UTC 2014


On 7/9/14, 4:51 PM, Matt Riedemann wrote:
>
>
> On 6/12/2014 6:17 AM, Daniel P. Berrange wrote:
>> On Thu, Jun 12, 2014 at 07:07:37AM -0400, Sean Dague wrote:
>>> On 06/12/2014 06:59 AM, Daniel P. Berrange wrote:
>>>> Does anyone have any tip on how to actually run individual tests in an
>>>> efficient manner. ie something that adds no more than 1 second penalty
>>>> over & above the time to run the test itself. NB, assume that i've
>>>> primed
>>>> the virtual env with all prerequisite deps already.
>>>>
>>>
>>> The overhead is in the fact that we have to discover the world, then
>>> throw out the world.
>>>
>>> You can actually run an individual test via invoking the testtools.run
>>> directly:
>>>
>>>> python -m testtools.run nova.tests.test_versions
>>>
>>> (Also, when testr explodes because of an import error this is about the
>>> only way to debug what's going on).
>>
>> Most excellent, thankyou. I knew someone must know a way to do it :-)
>>
>> Regards,
>> Daniel
>>
>
> I've been beating my head against the wall a bit on unit tests too
> this week, and here is another tip that just uncovered something for
> me when python -m testtools.run and nosetests didn't help.
>
> I sourced the tox virtualenv and then ran the test from there, which
> gave me the actual error, so something like this:
>
> source .tox/py27/bin/activate
> python -m testtools.run <test>
>
> Props to Matt Odden for helping me with the source of the venv tip.
Being kind of an outlaw in the testing world, when hitting individual
tests I typically am using py.test.   It has a way way nicer interface
than the testtools stuff, when things don't import correctly you get an
actual informative error message rather than ten screenfuls of garbage,
stuff like that.    You can point it at the .py file of the test,
instead of the module path, so that shell completion can be used to find
what you're looking for, e.g. py.test tests/ -->  tests/sqlalchemy/  
--> tests/sqlalchemy/test_migrations.py.

I typically never use tox or testtools at the commandline until I'm
ready to commit and want to see what the jenkins builds will see.   I
start up the whole thing and then it's time to take a break while it
reinvents the whole world.















More information about the OpenStack-dev mailing list