[TIP] problems w/ coverage and threads?
Dirk Pranke
dpranke at chromium.org
Tue Aug 24 21:36:19 PDT 2010
Hi Ned,
Thanks for the response. I've verified that if I pull the code into a
function called by run(), it works for me as well, which gives me a
pretty good workaround in the meantime.
Would it be helpful for me to file this as a bug?
-- Dirk
On Tue, Aug 24, 2010 at 7:43 PM, Ned Batchelder <ned at nedbatchelder.com> wrote:
> Hi Dirk,
>
> Indeed I can reproduce this. I don't understand why yet, but the run()
> method is not recorded by the trace function, but functions it calls are.
> Odd. I'll work more on it..
>
> --Ned.
>
> On 8/24/2010 2:36 PM, Dirk Pranke wrote:
>>
>> Hi all,
>>
>> I'm running the following program under coverage on a Mac Pro running
>> Snow Loepard (using "coverage run threads_unittest.py", python 2.5,
>> coverage 3.3.1) and getting no coverage numbers from the
>> TestThread.run()
>> method. Also, if I try to mark it ignored with "# pragma: no cover",
>> that seems to have no effect.
>>
>> I would have thought that both of these things would work. Any ideas?
>>
>> -- Dirk
>>
>> % cat threads_unittest.py
>>
>> import Queue
>> import threading
>> import unittest
>>
>> class TestThread(threading.Thread):
>> def __init__(self, started_queue, stopping_queue):
>> threading.Thread.__init__(self)
>> self._started_queue = started_queue
>> self._stopping_queue = stopping_queue
>>
>> def run(self):
>> print "starting thread"
>> self._started_queue.put('')
>> msg = self._stopping_queue.get()
>> print "exiting thread"
>>
>> class ThreadTest(unittest.TestCase):
>> def test_threads(self):
>> starting_queue = Queue.Queue()
>> stopping_queue = Queue.Queue()
>> thd = TestThread(starting_queue, stopping_queue)
>> stopping_queue.put('')
>> thd.start()
>> starting_queue.get()
>> thd.join()
>> self.assertTrue(True)
>>
>> if __name__ == '__main__':
>> unittest.main()
>> %
>>
>> _______________________________________________
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
>> http://lists.idyll.org/listinfo/testing-in-python
>>
>
More information about the testing-in-python
mailing list