-
-
Notifications
You must be signed in to change notification settings - Fork 448
return statement is not stated as covered despite executed and asserted by tests #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This test looks wrong to me. You are inside an assert_raises clause, which means you believe your hander._save() function call will raise that exception. If you test passes, it must mean that your function call actually raised that OperationFailure exception. Therefore your last two assertEqual statements are never executed. You have to decide if you want the function to raise the exception, in which case keep the assert_raises and remove the assertEquals, or you want the function to return a value, in which case remove the assert_raises. It could be that you are importing OperationFailure differently in the test code and the product code, and that is why the except clause in the product code isn't catching the exception. |
Original comment by lc3t35 (Bitbucket: lc3t35, GitHub: lc3t35) Thank Ned for your review, you are absolutly right, last two assertEqual are not executed.
and the test :
Test is OK but coverage indicates the 3 last lines are not covered |
OK, glad we got to the bottom of it. |
The last three lines in your product code are marked as not run because they are not actually run. The only reason your assert_raises test succeeds is because your product code actually raises that exception. When I say it raises it, I don't mean that it raises it and catches it and handles it. I mean that the exception actually is raised from your function into the caller. Your except clause is not executing in your product code. |
If the three lines of your function were executing, then your function would complete normally, which will make your assert_raises call fail your test. But your test isn't failing. |
Usually when this happens, it's because you've imported the name OperationFailure in two different ways. In your code, there are three references to OperationFailure: 1) the actual code that raises the exception (probably in your database library), 2) in the except clause in your product code, and 3) in the assert_raises function call in your test. It seems that #1 and #3 are referring to the same class, and #2 is referring to a different class. Closely examine how you are importing the exception to see if they are being imported the same. |
Original comment by lc3t35 (Bitbucket: lc3t35, GitHub: lc3t35) Both are declared as
I replaced both with import pymongo.errors and use pymongo.errors.OperationFailure instead, same behaviour. The exception is raised inside the test but not handled in the product code. |
Originally reported by lc3t35 (Bitbucket: lc3t35, GitHub: lc3t35)
Here is the code
Here is the test :
Test is OK of course
The text was updated successfully, but these errors were encountered: