2

I need to write test using unittest in python that fails when coverage is less than 50 percent. Such as:

class ExampleTest(unittest.TestCase):

def setUp(self):
    cov = coverage.Coverage()
    cov.load()
    with open(os.devnull, "w") as f:
        self.total = cov.report(file=f)

def test_compare_values(self):
    self.assertGreaterEqual(self.total, 20)

But when tests are running the file coverage is locked and cannot be opened.

How solve this problem?

1 Answer 1

1

Don't try to read the coverage data from a test. Instead use the --fail-under=50 option on the coverage report command.

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.