proud-planet-36170
10/30/2024, 9:53 PMunittest.mock.patch
is tripping up pants
patcher = unittest.mock.patch(
"snowflake.ingest.SimpleIngestManager",
return_value=unittest.mock.MagicMock(autospec=True),
)
> ingest_manager_constructor = patcher.start()
dms-object-manager/dms_object_manager/test_snowflake_lz.py:64:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py:1594: in start
result = self.__enter__()
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/mock.py:1430: in __enter__
self.target = self.getter()
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/pkgutil.py:700: in resolve_name
mod = importlib.import_module(modname)
/opt/homebrew/Cellar/python@3.11/3.11.9_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:126: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1204: in _gcd_import
???
<frozen importlib._bootstrap>:1176: in _find_and_load
???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'snowflake', import_ = <function _gcd_import at 0x10456bd80>
> ???
E ModuleNotFoundError: No module named 'snowflake'
Adding import snowflake.ingest
to the test file fixes it but not sure if there's a better waybroad-processor-92400
10/30/2024, 10:12 PMpatch.object
, e.g. from snowflake import ingest
patch.object(ingest, ingset.SimpleIngestManager.__name__, ...)
since that works better with "find references" etc. ... although that's most useful when mocking first-party code rather than external dependencies. This'll work well with Pants' inference, as a side effect.)
• adding dependencies=["path/to#snowflake"]
(or whatever the dependency name is) in the BUILD file
• using https://www.pantsbuild.org/stable/reference/subsystems/python-infer#string_imports to infer from strings like thatproud-planet-36170
10/31/2024, 12:20 AM