8000 [BE] Do not use `assert` in unit tests · pytorch/pytorch@8976cf4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8976cf4

Browse files
authored
[BE] Do not use assert in unit tests
One should always use `unittest.assert` methods rather than plain `assert` as later can be turned into a noop if Python runtime is invoked with optimizations enabled Fixes use of `assert` introduced by #105251
1 parent 5ef5f1a commit 8976cf4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

.github/scripts/test_trymerge.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ class TestGitHubPRGhstackDependencies2(TestCase):
865865
def test_pr_dependencies(self, *args: Any) -> None:
866866
pr = GitHubPR("pytorch", "pytorch", 106068)
867867
msg = pr.gen_commit_message(filter_ghstack=True)
868-
assert msg == (
868+
self.assertEqual(msg,
869869
"[FSDP] Break up `_post_backward_hook` into smaller funcs (#106068)\n\n\nDifferential Revision: ["
870870
"D47852461](https://our.internmc.facebook.com/intern/diff/D47852461)\nPull Request resolved: "
871871
"https://github.com/pytorch/pytorch/pull/106068\nApproved by: \n"
@@ -878,7 +878,7 @@ def test_pr_dependencies_ghstack(self, *args: Any) -> None:
878878
pr = GitHubPR("pytorch", "pytorch", 106068)
879879

880880
msg = pr.gen_commit_message(filter_ghstack=True, ghstack_deps=[pr0, pr1, pr2])
881-
assert msg == (
881+
self.assertEqual(msg,
882882
"[FSDP] Break up `_post_backward_hook` into smaller funcs (#106068)\n\n\nDifferential Revision: ["
883883
"D47852461](https://our.internmc.facebook.com/intern/diff/D47852461)\nPull Request resolved: "
884884
"https://github.com/pytorch/pytorch/pull/106068\nApproved by: \n"
@@ -931,7 +931,7 @@ def test_merge_ghstack_into(
931931
mock_repo.cherry_pick.assert_any_call("rev2")
932932
mock_repo.cherry_pick.assert_any_call("rev123")
933933

934-
assert mock.call("rev1") not in mock_repo.cherry_pick.call_args_list
934+
self.assertTrue(mock.call("rev1") not in mock_repo.cherry_pick.call_args_list)
935935

936936
# Verify the first call
937937
message = mock_repo.amend_commit_message.call_args_list[0].args[0]
@@ -944,8 +944,8 @@ def test_merge_ghstack_into(
944944
"dependencies: #106032, #106033\n"
945945
)
946946

947-
assert message.startswith(prefix)
948-
assert message.endswith(suffix)
947+
self.assertTrue(message.startswith(prefix))
948+
self.assertTrue(message.endswith(suffix))
949949

950950
# Verify the second call
951951
mock_repo.amend_commit_message.assert_any_call(

0 commit comments

Comments
 (0)
0