python 2.7 - how to test class private method in nosetest -
how test class private method in nosetest ?
my code
class txt(object): """docstring txt""" def __init__(self, im_file): super(txt, self).__init__() self.im_file = im_file @classmethod def __parse_config(cls, im_file): line in im_file: print(line) pass
my nosetest
class testtxt(object): """docstring testtxt""" @classmethod def setup_class(cls): cls.testing_file = '\n'.join([ 'rtsp_link: rtsp://172.19.1.101', ]) def test_load(self): txt.parse_config(stringio(self.testing_file)) pass
you can access txt.__parse_config()
private method prepending class name before method name: txt._txt__parse_config()
.
demo:
>>> class a(): ... _private = 1 ... __super_private = 2 ... >>> a._private 1 >>> a.__super_private traceback (most recent call last): file "<stdin>", line 1, in <module> attributeerror: class has no attribute '__super_private' >>> a._a__super_private 2
for more info on happening, see what meaning of single- , double-underscore before object name?.
hope helps.
Comments
Post a Comment