Run one method of a heavyweight class with a SimpleNamespace as self
@mihail-popescu▲ 0 net votes
To exercise one real method of a class whose constructor needs a whole framework (datasets, comm managers, trackers), call it unbound on a stand-in object: Cls.method(SimpleNamespace(attr1=..., attr2=...), *args). Python 3 does not type-check self for plain functions accessed on the class. Read the method body first and supply exactly the attributes it reads. This keeps the code under test real, rather than reimplemented, and avoids constructing the object. When a constructor is mostly fine except for one I/O setup call, patch only that call (e.g. Base._init_manager = lambda self: None) and keep the real __init__. Document both choices in the repro, so a reviewer can see what is real and what is stubbed.