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


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

Re: unittest and threading

Started byMark Hammond <skippy.hammond@gmail.com>
First post2012-01-25 22:24 +1100
Last post2012-01-25 22:24 +1100
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: unittest and threading Mark Hammond <skippy.hammond@gmail.com> - 2012-01-25 22:24 +1100

#19395 — Re: unittest and threading

FromMark Hammond <skippy.hammond@gmail.com>
Date2012-01-25 22:24 +1100
SubjectRe: unittest and threading
Message-ID<mailman.5069.1327490700.27778.python-list@python.org>
Let me have a guess :)

On 25/01/2012 7:42 PM, Ross Boylan wrote:
> On Tue, 2012-01-24 at 13:54 -0800, Ross Boylan wrote:
...
> The code I want to test uses threads, but that is not entirely internal
> from the standpoint of the unit test framework.  The unit test will be
> executing in one thread, but some of the assertions may occur in other
> threads.  The question is whether that will work, in particular whether
> assertion failures will be properly captured and logged by the test
> framework.

I think it will - so long as your "test" on the main thread hasn't 
returned yet.

> Concretely, a test may exercise some code that triggers a callback; the
> callback might come in a different thread, and the code that is
> triggered might make various assertions.
>
> There are two issues: whether assertions and their failures that happen
> in other threads will be correctly received by the test framework, and
> whether the framework is robust against several assertions being raised
> "simultaneously" in different threads.  The latter seems a bit much to
> hope for.

I suspect both will be fine.

>
> I assume that, at a minimum, the my test code will need to use locks or
> other coordination mechanisms so the test doesn't end before all code
> under test executes.

Yep - that's the only caveat I'd expect .

> Finally, I'll mention two senses of threads in tests that my question
> does not concern, although they are also interesting.
>
> I am not concerned with testing the performance of my code, in the sense
> of asserting  that an operation must complete before x seconds or after
> y seconds.  Some potential implementations of such tests might use
> threads even if the code under test was single-threaded.
>
> The question also does not concern running lots of unit tests in
> parallel.

nose is still worth having a look at - personally I just use it as a 
runner and where possible ignore its api...

Mark

[toc] | [standalone]


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


csiph-web