Code Review Doctor suggests a fix if your code does not follows Python testing best practices.
This gives you greater confidence in the quality of your tests because it is not what you test that is important, but how you test.
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | self.assertEquals(int('1'), 1) |
Don't use deprecated TestCase
assertions like self.assertEquals
. Use their modern counterpart instead like self.assertEqual
.
- | self.assertEquals(int('1'), 1) |
+ | self.assertEqual(int('1'), 1) |
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | self.assertTrue(value_one, value_two) |
assertTrue
is not for comparing arguments. Consider assertEqual
or others instead.
- | self.assertTrue(value_one, value_two) |
+ | self.assertEqual(value_one, value_two) |
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | self.assertTrue(value in values) |
assertIn
and assertNotIn
provide more helpful failure messages than assertTrue
or assertFalse
.
- | self.assertTrue(value in values) |
+ | self.assertIn(value, values) |
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | self.assertTrue(value is not None) |
assertIsNone
and assertIsNotNone
provide more helpful failure messages than assertTrue
or assertFalse
.
- | self.assertTrue(value is not None) |
+ | self.assertIsNotNone(value) |
1 | + | class TestFeature(unittest.TestCase): | |
2 | + | def test_feature(self): | |
3 | + | ... | |
4 | + | ||
5 | + | def test_feature(self): |
Duplicate names for tests results in some tests being skipped.
Read more- | def test_feature(self): |
+ | def test_feature_two(self): |
6 | + | ... |
Are you ready to improve your team agility through lower tech debt? Add Code Review Doctor to GitHub.