Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Coverage Report Python

Hi,

I have written almost every possible unit case for area of circle module but the coverage reports shows around 30%.

You can check folder for circle.py module and tests.py for tests.

https://w.trhou.se/pfsvl2k8er

Please let me know how I can ensure at least 95% coverage.

Kenneth Love

2 Answers

You are so close! I suspect you unit tests aren't ever running, because tests.py line 18 has a variable that isn't defined anywhere.

Try adding

test.py
# [...]
if __name__ == '__main__':
    unittest.main()

To the end of tests.py. Fix tests.py line 18 (maybe just comment it out? not sure what i is supposed to be.

Then:

$ coverage run tests.py
$ coverage report
Name        Stmts   Miss  Cover
-------------------------------
circle.py       7      0   100%
tests.py       15      0   100%
-------------------------------
TOTAL          22      0   100%

Think about running your unit tests when the code is known to be broken. Sometimes when I write unit tests after I already have what I think is working code, I comment out key parts so that I know it's broken, then run the tests just to make sure it's testing what I think it should be testing.

ps: you may think about removing that final else: in aoc(). You don't need it, the code is clearer if less of it is indented.

Myers Carpenter I figured it out later, that main part was missing. Thanks for providing the detailed explanation.