1

I am using coverage to check which unit tests to write. I'm checking in accounts/views.py, for which I haven't written any tests, but why it's not showing tests missing case(i.e in red)?

I expect around 50+ statements to be in error stage, excluding imports to write tests. But it's like 50% doesn't need any tests!

coverage html for views

Timer
  • 37
  • 1
  • 7

1 Answers1

2

The lines in a class statements are executed when the class is defined, that is, when the file is imported. Even though the classes are never used, they are defined, so the class line, and all the lines immediately within it, are executed when the file is imported.

Notice that the one line you have inside a method (line 26) is marked as red, because it was never executed.

Ned Batchelder
  • 364,293
  • 75
  • 561
  • 662
  • Sorry, I didn't get it still! what do you mean? that if class statements are executed, then it won't need tests? That means my SignUp view needs no testing according to this coverage package? – Timer Jun 29 '18 at 17:13
  • I mean that coverage can't tell if this class is used in your tests or not. Coverage is not perfect: it can only tell you if a line of code was run or not. It can't tell you if the object made by the line of code was used, or used properly. – Ned Batchelder Jun 29 '18 at 23:58
  • Ok, I got it, I am excited that creator of the package itself answered :) Also, I am a fan of you! Thank you! – Timer Jun 30 '18 at 04:51