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


Groups > comp.lang.python > #19374 > unrolled thread

unittest and threading

Started byRoss Boylan <ross@biostat.ucsf.edu>
First post2012-01-24 13:54 -0800
Last post2012-01-25 07:47 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  unittest and threading Ross Boylan <ross@biostat.ucsf.edu> - 2012-01-24 13:54 -0800
    Re: unittest and threading Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-25 07:47 +0000

#19374 — unittest and threading

FromRoss Boylan <ross@biostat.ucsf.edu>
Date2012-01-24 13:54 -0800
Subjectunittest and threading
Message-ID<mailman.5053.1327443409.27778.python-list@python.org>
Is it safe to use unittest with threads?

In particular, if a unit test fails in some thread other than the one
that launched the test, will that information be captured properly?

A search of the net shows a suggestion that all failures must be
reported in the main thread, but I couldn't find anything definitive.

If it matters, I'm using CPython 2.7.

Thanks.  If you're using email, I'd appreciate a cc.
Ross Boylan

[toc] | [next] | [standalone]


#19387

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2012-01-25 07:47 +0000
Message-ID<4f1fb3ab$0$29971$c3e8da3$5496439d@news.astraweb.com>
In reply to#19374
On Tue, 24 Jan 2012 13:54:23 -0800, Ross Boylan wrote:

> Is it safe to use unittest with threads?

I see nobody else has answered, so I'll have a go.

I think you need to explain what you mean here in a little more detail.

If you mean, "I have a library that uses threads internally, and I want 
to test it with unittest", then the answer is almost certainly yes it is 
safe.

If you mean, "I want to write unit tests which use threads as part of the 
test", then the answer again remains almost certainly yes it is safe.

Provided, of course, that your test code is not buggy. Tests, being code, 
are not immune to bugs, and the more complex your tests, the more likely 
they contain bugs.

Lastly, if you mean, "I want to execute each unit test in a separate 
thread, so that all my tests run in parallel instead of sequentially", 
then the answer is that as far as I know the unittest framework does not 
support this.

You would have to write your own framework. You might be able to inherit 
some of the behaviour from the unittest module, but all the threading 
would be up to you. So only you will know whether it will be safe or not.

Alternatively, you could try the nose or py.test frameworks, which I 
understand already support running tests in parallel.


-- 
Steven

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web