[TIP] How do you unit test threading classes?

Tiemo Kieft t.kieft at infinitesimal.nl
Fri Jun 6 01:28:30 PDT 2014


Hi,

> I would love if there was a Mock or something that executed a function
> line by line, letting you do checks. There would be no easier way than
> that to assert you are doing things correctly.

But that won't tell you anyting, the problem with threading is that
there is absolutely
no way to know what piece of code gets executed at what time (unless
you employ some
kind of serialisation scheme such as a Lock, which negatively impacts
parallelism.) The
granulairty is much finer then 'lines of code', so running it line by
line won't yield any
useful information.

Another option would be to go non-blocking, for instance using Python
3.4's new async
module.

-- 
- Tiemo



More information about the testing-in-python mailing list