即使值不同,AssertEqual 也不会抛出错误

AssertEqual Doesnt Throw an Error even if Values are Different

我在 Python

中有此代码
import unittest



class AES_TEST(unittest.TestCase):


    def test_encryption(self):
        print('Encryption : ')
        plaintext = 0x3243f6a8885a308d313198a2e0370734
        encrypted = 75960790320075369159181001580855561010
        print(encrypted)
        print('0x3925841d02dc09fbdc118597196a0b32')

        self.assertEqual(encrypted, 0x3925841d02dc09fbdc118597196a0b32)

    def test_decryption(self):
        print('Decryption : ')
        ciphertext = 0x3925841d02dc09fbdc118597196a0b32
        decrypted = self.AES.decrypt(ciphertext)
        decrypted = 66814286504060421741230023322616923956
        print(decrypted)
        print('0x3243f6a8885a308d313198a2e0370734')


        self.assertEqual(decrypted, 0x3243f6a8885a308d313198a2e0370734)

if __name__ == '__main__':
    unittest.main()

为什么不报错?为什么 encrypted 变量等于 0x3925841d02dc09fbdc118597196a0b32 ,而实际上它们具有不同的值?在 decryption 变量中也观察到相同的行为。

他们是平等的。

数字前面的 0x 表示表示为基数 16(十六进制)。如果您使用 calculator0x3925841d02dc09fbdc118597196a0b32 转换为十进制格式,您将看到它与在该代码块中分配给它的值相同。