我试图在我使用的外部模块中对函数进行monkeypatch,但是monkeypatch似乎无法访问该函数,因为导入时该模块的命名空间被覆盖。
具体来说,我使用
Bio.PDB.PDBList.PDBList
biopython
模块),我正在尝试修补
_urlretrieve
在里面
Bio.PDB.PDBList
PDBList
这将是实质上更多的工作。但当我尝试中堂时:
m.setattr("Bio.PDB.PDBList._urlretrieve", mock_retrieve)
pytest抱怨:
AttributeError: 'type' object at Bio.PDB.PDBList has no attribute '_urlretrieve'
关于进一步检查
Bio.PDB
.PDBList
似乎被全班覆盖了
.PDBList.PDBList
:
# Download from the PDB
from .PDBList import PDBList
生物.PDB.PDBList
作为一个
type
_URL检索
. 我的问题是,有没有办法让monkeypatch修补这个“隐藏”功能?
PDB列表
班级:
from Bio.PDB.PDBList import PDBList
_pdblist = PDBList()
downloaded_file = _pdblist.retrieve_pdb_file('2O8B', pdir='./temp', file_format='pdb')