``` from unittest.mock import patch _print = print with patch('builtins.print') as mock: mock.side_effect = lambda x: _print("whatever you want") import a ```
LeeReamond
2021-08-07 03:49:23 +08:00
@aijam 你好,我没有理解这段代码的逻辑 下面的代码我试了输出结果是 hello world ``` from unittest.mock import patch
_print = print with patch('builtins.print') as mock: mock.side_effect = lambda x: _print("whatever you want")