Why is My PyTest Passing When It Should Be Failing?
Hello!
Quick one today: I was showing someone some pytests I had written when I noticed that my test was wrong: that is the expected and actual did not match. This seemed odd to me as I had written the tess some weeks ago and it ran successfully both on the build and also locally. This is where my test was asserting actual as expected…
expected_test_add_all_failed_test_cases == actual_test_add_all_failed_test_cases
… except of course, it wasn’t! What I had failed to do is add the assert
keyword to verify that the two objects were equal. What I’m getting a is false returned, but no actual failed test. This is a silly thing to occur but it is one of those things you can burn a lot of time on because you’re probably not going to see it until it is blatantly pointed out to you. So now I added assert
and my test failed. Excellent! Well, not really, but you know what I mean :-)
assert expected_test_add_all_failed_test_cases == actual_test_add_all_failed_test_cases