Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #2878

Re: Creating unit tests on the fly

From Raymond Hettinger <python@rcn.com>
Newsgroups comp.lang.python
Subject Re: Creating unit tests on the fly
Date 2011-04-08 14:50 -0700
Organization http://groups.google.com
Message-ID <e2a1efe6-17bb-4d94-8fcc-b812b41f6b75@d28g2000yqf.googlegroups.com> (permalink)
References <55ab5243-da42-4933-b3e5-b8189698b11e@m13g2000yqb.googlegroups.com>

Show all headers | View raw


On Apr 8, 12:10 pm, Roy Smith <r...@panix.com> wrote:
> I can even create new test cases from these on the fly with something
> like:
>
>  newClass = type("newClass", (BaseSmokeTest,), {'route': '/my/newly/
> discovered/anchor'})
>
> (credit tohttp://jjinux.blogspot.com/2005/03/python-create-new-class-on-fly.html
> for that neat little trick).  The only thing I don't see is how I can
> now get unittest.main(), which is already running, to notice that a
> new test case has been created and add it to the list of test cases to
> run.  Any ideas on how to do that?

The basic unittest.main() runner isn't well suited to this task.  It
flows in a pipeline of discovery -> test_suite -> test_runner.

I think you're going to need a queue of tests, with your own test
runner consuming the queue, and your on-the-fly test creator running
as a producer thread.

Writing your own test runner isn't difficult.  1) wait on the queue
for a new test case. 2) invoke test_case.run() with a TestResult
object to hold the result 3) accumulate or report the results 4)
repeat forever.

Raymond

twitter: @raymondh

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Creating unit tests on the fly Roy Smith <roy@panix.com> - 2011-04-08 12:10 -0700
  Re: Creating unit tests on the fly Raymond Hettinger <python@rcn.com> - 2011-04-08 14:50 -0700
    Re: Creating unit tests on the fly Ben Finney <ben+python@benfinney.id.au> - 2011-04-09 08:46 +1000
      Re: Creating unit tests on the fly Roy Smith <roy@panix.com> - 2011-04-08 22:02 -0400
        Re: Creating unit tests on the fly Ben Finney <ben+python@benfinney.id.au> - 2011-04-09 12:15 +1000
    Re: Creating unit tests on the fly Roy Smith <roy@panix.com> - 2011-04-10 22:45 -0400

csiph-web