Andrei.Danciuc
Andrei.Danciuc

Reputation: 1137

Unbuffered python coverage

I want to run application in production with coverage enable. The application is always up and do not stop its execution. In each day I want to see coverage increase. Unfortunately .coverage file appear on the disk only after application stop.

To simulate this behavior I have test.py

# cat test.py 
if 1==2:
    print(1)

if 2==2:
    print(2)

import time

i = 10
while i:
    print("sleep")
    time.sleep(1)
    i -= 1

print("end")

Which is launched like

python3 -u -m coverage run test.py 
2
sleep
sleep
sleep
sleep # I want to be able to see coverage in this moment
sleep
sleep
sleep
sleep
sleep
sleep
end

Only after end word is printed I can see coverage file

ls -a
.  ..  .coverage  test.py

How can I force flushing/Unbuffering on py.coverage ?

Upvotes: 1

Views: 186

Answers (1)

Ned Batchelder
Ned Batchelder

Reputation: 375854

There is no way to get coverage.py 4.5.1 to do this. The 5.0 development switched the data storage to SQLite, so we should be able to add a feature to periodically flush the coverage data to the database.

Upvotes: 1

Related Questions