coveragepy: Executed lines reported as missing in threads
Originally reported by k3it (Bitbucket: k3it, GitHub: k3it)
I apologize for a cross post from http://stackoverflow.com/q/43991865/1653558 but it looks like this is a better place for the report
I’m getting some low coverage numbers on script with threads activated with a run() method. It seems that the coverage module is unable to keep track of all hits. Here is the code that demonstrates the problem. Running it should produce 100% coverage, but I’m getting 71.
#!python
from threading import Thread
class MyNestedThread(Thread):
def run(self):
print("hello from the nested thread!")
class MyThread(Thread):
def run(self):
print("Hello from thread")
t = MyNestedThread()
t.start()
return
if __name__ == '__main__':
for i in range(3):
t = MyThread()
t.start()
#!python
Hello from thread
hello from the nested thread!
Hello from thread
Hello from thread
hello from the nested thread!
hello from the nested thread!
Name Stmts Miss Cover
----------------------------
foo.py 14 4 71%
re-running ‘coverage run foo.py’ sometimes gives a different %, and even 100% on occasion.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 41 (22 by maintainers)
Threads won’t be measured unless you specify them as part of your concurrency setting: