unittest.mock.patch does not work properly (the objects are not patched at all!) in SwiftTest.
Expected behavior
For example, if we do unittest.mock.patch("swift.dumps"), then calling swift.dumps() should be mocked.
To Reproduce
Steps to reproduce the behavior:
Write a test in SwiftTest
Use unittest.mock.patch
See error
Expected causes and correction methods
I found that patching uses importlib.import_module(), by inspecting mock_calls of the mocked import_modules().
Therefore, we should be careful when patching importlib.import_module().
We should not replace importlib.import_module() permanently.
If we have to, we may patch it temporarily.
Describe the bug
unittest.mock.patch
does not work properly (the objects are not patched at all!) inSwiftTest
.Expected behavior
For example, if we do
unittest.mock.patch("swift.dumps")
, then callingswift.dumps()
should be mocked.To Reproduce
Steps to reproduce the behavior:
SwiftTest
unittest.mock.patch
Expected causes and correction methods
I found that patching uses
importlib.import_module()
, by inspectingmock_calls
of the mockedimport_modules()
. Therefore, we should be careful when patchingimportlib.import_module()
. We should not replaceimportlib.import_module()
permanently. If we have to, we may patch it temporarily.Additional context
This issue is found while developing #163.