1
votes

How do I test the following code with unittest?

       with os.fdopen(os.open(file_path, flags, 0o640), "w") as f:
            f.write(result_str)
            os.fsync(f)

I have tried method below, but it didn't work out

@patch("os.open", MagicMock())
@patch("os.fdopen", MagicMock())
def test_func_should_ok_param_is_ok(self):
    ret = AS().wrd() # This function contains the part above that I have to test
    assert ret
"but it didn't work out". Exactly how does it not work out? - blhsing
Hello @Tonya, welcome to Stack Overflow. Could you elaborate more the question and the problem you are facing? So people could help you better. - Mauro Baraldi