2

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 ?

7
  • I don't understand what you mean by, "In each day I want to see the coverage increase." Why would your application run code on the second day that it didn't run on the first day? Commented Oct 2, 2018 at 23:38
  • it is an interactive application. In day 1 get input A, in day 2 get input B, in day 3 get a combination of A and B so there are 3 branches to cover for three days Commented Oct 3, 2018 at 8:53
  • What is it you will learn from this coverage measurement? Do you have an automated test suite that can give you coverage numbers? Commented Oct 3, 2018 at 12:06
  • 1
    @NedBatchelder I am searching for a solution about HOW ant not WHY to solve something. 1. Of course I do not have automated case for input D,E,F ... (I have only for A, B and C). 2. QA are doing some test each day and I need to be sure that they did their jobs properly. Commented Oct 3, 2018 at 13:37
  • 1
    When I get unusual questions from people using coverage.py, I like to find out as much as I can about their uses. It helps me build a better product. Commented Oct 3, 2018 at 18:03

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.