[TIP] Custom execution of nose tests

Kumar McMillan kumar.mcmillan at gmail.com
Fri Jul 22 15:50:19 PDT 2011


On Thu, Jul 21, 2011 at 1:32 PM, Alex Gaynor <alex.gaynor at gmail.com> wrote:
> Thanks, should I be able to safely pickle a test instance?

Not out of the box.  You can make a lightweight wrapper and pickle
that -- this is what the multiprocessing plugin does to bounce test
cases across processes.  See nose.plugins.multiprocessing.TestLet for
ideas.

> It seems to be
> working mostly ok, except on deserialization I'm getting:
> Traceback (most recent call last):
>   File "/home/alex/ans/web/lib/a/test/__init__.py", line 311, in
> execute_test
>     a.lib.execute_on_cpython(run_test_proxy)(test)
>   File "/home/alex/ans/web/lib/a/lib.py", line 1137, in wrapper
>     return pickle.loads(channel.receive())
>   File "/home/alex/ans/venv/lib/pypy/site-packages/execnet/gateway_base.py",
> line 413, in receive
>     raise self._getremoteerror() or EOFError()
> RemoteError: Traceback (most recent call last):
>   File "/home/alex/ans/venv/lib/pypy/site-packages/execnet/gateway_base.py",
> line 735, in executetask
>     function(channel, **kwargs)
>   File "", line 10, in cpython_runner
>   File "/home/alex/ans/venv/lib/python2.6/pickle.py", line 1374, in loads
>     return Unpickler(file).load()
>   File "/home/alex/ans/venv/lib/python2.6/pickle.py", line 858, in load
>     dispatch[key](self)
>   File "/home/alex/ans/venv/lib/python2.6/pickle.py", line 1217, in
> load_build
>     setstate(state)
>   File "/home/alex/ans/venv/lib/pypy/site-packages/nose/config.py", line
> 238, in __setstate__
>     self.plugins.configure(self.options, self)
>   File "/home/alex/ans/venv/lib/pypy/site-packages/nose/plugins/manager.py",
> line 271, in configure
>     cfg(options, config)
>   File "/home/alex/ans/venv/lib/pypy/site-packages/nose/plugins/manager.py",
> line 94, in __call__
>     return self.call(*arg, **kw)
>   File "/home/alex/ans/venv/lib/pypy/site-packages/nose/plugins/manager.py",
> line 162, in simple
>     result = meth(*arg, **kw)
>   File "/home/alex/ans/venv/lib/pypy/site-packages/nose/plugins/prof.py",
> line 76, in configure
>     if options.profile_stats_file:
> AttributeError: Values instance has no attribute 'profile_stats_file'
>
> Any idea what's up with this?
> Alex
> On Thu, Jul 21, 2011 at 11:07 AM, jason pellerin <jpellerin at gmail.com>
> wrote:
>>
>> I'm away from my main computer right now so I can't give very good
>> examples but here's a poor one:
>>
>> http://packages.python.org/nose/plugins/collect.html (scroll down to
>> the plugin source; poor because most plugins won't have to worry about
>> making plugin calls themselves like that one does).
>>
>> Basically, prepareTestCase gets a nose.case.Test and you can twiddle
>> that (or not) and return None, or return a callable that will be
>> called with the test result and can do whatever it wants and use that
>> result to record the outcome.
>>
>> JP
>>
>> On Thu, Jul 21, 2011 at 1:55 PM, Alex Gaynor <alex.gaynor at gmail.com>
>> wrote:
>> > Sorry, I should have been more clear, I understand it's supposed to
>> > return a
>> > callable, I just need to understand what exactly that callable is
>> > supposed
>> > to do, essentially, is there an example of what the "default"
>> > prepareTestCase does?  Also, returning None simply triggers the default
>> > behavior, right?
>> > Alex
>> >
>> > On Wed, Jul 20, 2011 at 10:33 PM, Kumar McMillan
>> > <kumar.mcmillan at gmail.com>
>> > wrote:
>> >>
>> >> On Wed, Jul 20, 2011 at 11:46 PM, Alex Gaynor <alex.gaynor at gmail.com>
>> >> wrote:
>> >> > Err, are there any docs with an example of what prepareTestCase
>> >> > should
>> >> > return?
>> >>
>> >> Hi Alex.  prepareTestCase just needs to return a callable.  When
>> >> called, it runs the test.  You can also look at nose.case.Test.  A
>> >> subclass of that would be an adequate return value.
>> >>
>> >> As an aside, you may want to check out nosepipe, a plugin that
>> >> collects tests then runs each one in a subprocess:
>> >> http://pypi.python.org/pypi/nosepipe/  It's not an elegant solution to
>> >> what you're after but probably implements a lot of the same hooks.
>> >>
>> >> -Kumar
>> >>
>> >>
>> >> > Thanks,
>> >> > Alex
>> >> >
>> >> > On Wed, Jul 20, 2011 at 9:16 PM, Alex Gaynor <alex.gaynor at gmail.com>
>> >> > wrote:
>> >> >>
>> >> >> Synchronous, normal style is totally fine, so it looks like
>> >> >> prepareTestCase is the right call.  Thanks.
>> >> >> Alex
>> >> >>
>> >> >> On Wed, Jul 20, 2011 at 6:32 PM, jason pellerin
>> >> >> <jpellerin at gmail.com>
>> >> >> wrote:
>> >> >>>
>> >> >>> That's a fun one. Do you want to wait for cpython to execute each
>> >> >>> test, or send a bunch of tests over to process/process pool and
>> >> >>> collect the results later?
>> >> >>>
>> >> >>> The wait case is not so hard -- you can write a plugin that
>> >> >>> implements
>> >> >>> prepareTestCase* to wrap the test in the cpythonizing machinery,
>> >> >>> run
>> >> >>> it, and report the result.
>> >> >>>
>> >> >>> The queue and collect case is sort of a special case of
>> >> >>> multiprocessing which requires writing a new test runner and is
>> >> >>> harder. But basically you write whatever test runner you want and
>> >> >>> use
>> >> >>> the prepareTestRunner** plugin hook to inject it.
>> >> >>>
>> >> >>> Also we really need to add pypy to our tox config, Kumar. ;)
>> >> >>>
>> >> >>> JP
>> >> >>>
>> >> >>> *
>> >> >>>
>> >> >>>
>> >> >>>  http://packages.python.org/nose/plugins/interface.html#nose.plugins.base.IPluginInterface.prepareTestCase
>> >> >>>
>> >> >>> **
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>> http://packages.python.org/nose/plugins/interface.html#nose.plugins.base.IPluginInterface.prepareTestRunner
>> >> >>>
>> >> >>> On Wed, Jul 20, 2011 at 9:15 PM, Alex Gaynor
>> >> >>> <alex.gaynor at gmail.com>
>> >> >>> wrote:
>> >> >>> > Hi all,
>> >> >>> > I've got a fair insane question about nose.  I'd like to be able
>> >> >>> > to
>> >> >>> > control
>> >> >>> > how my nose tests are executed, specifically I'm running my suite
>> >> >>> > under
>> >> >>> > PyPy, but I'd like certain tests (in their entirety, setup, test,
>> >> >>> > teardown)
>> >> >>> > to be executed on CPython.  I have the machinery to send some
>> >> >>> > code
>> >> >>> > over
>> >> >>> > to
>> >> >>> > CPython to execute it, but what I'm missing is the ability to do
>> >> >>> > that
>> >> >>> > over
>> >> >>> > the entirety of a test run.  In py.test I believe this could be
>> >> >>> > accomplished
>> >> >>> > with a custom test collector.
>> >> >>> > Thanks,
>> >> >>> > Alex
>> >> >>> >
>> >> >>> > --
>> >> >>> > "I disapprove of what you say, but I will defend to the death
>> >> >>> > your
>> >> >>> > right to
>> >> >>> > say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
>> >> >>> > "The people's good is the highest law." -- Cicero
>> >> >>> >
>> >> >>> >
>> >> >>> > _______________________________________________
>> >> >>> > testing-in-python mailing list
>> >> >>> > testing-in-python at lists.idyll.org
>> >> >>> > http://lists.idyll.org/listinfo/testing-in-python
>> >> >>> >
>> >> >>> >
>> >> >>
>> >> >>
>> >> >>
>> >> >> --
>> >> >> "I disapprove of what you say, but I will defend to the death your
>> >> >> right
>> >> >> to say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
>> >> >> "The people's good is the highest law." -- Cicero
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > "I disapprove of what you say, but I will defend to the death your
>> >> > right
>> >> > to
>> >> > say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
>> >> > "The people's good is the highest law." -- Cicero
>> >> >
>> >> >
>> >> > _______________________________________________
>> >> > testing-in-python mailing list
>> >> > testing-in-python at lists.idyll.org
>> >> > http://lists.idyll.org/listinfo/testing-in-python
>> >> >
>> >> >
>> >
>> >
>> >
>> > --
>> > "I disapprove of what you say, but I will defend to the death your right
>> > to
>> > say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
>> > "The people's good is the highest law." -- Cicero
>> >
>> >
>
>
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." -- Evelyn Beatrice Hall (summarizing Voltaire)
> "The people's good is the highest law." -- Cicero
>
>



More information about the testing-in-python mailing list