我已经看过如何使用self调用另一个类中的函数的示例。但问题是我使用BDD的功能文件没有类定义。
如果这是另一种语言,我可以使用New运算符调用它并使用它的方法。
我不确定如何使用Python来做到这一点。
类:
MyDict *a = [MyDict new];
a[@"hi"] = @"there";
NSMutableDictionary *dict = [NSMutableDictionary new];
dict[@"some"] = a;
NSData *archive = [NSKeyedArchiver archivedDataWithRootObject:dict];
dict = [NSKeyedUnarchiver unarchiveObjectWithData:archive];
NSLog(@"%@", dict);
如果我想在一个特征文件中使用它,我将如何调用上面测试的方法,因为.feature只包含@given等步骤?
编辑:
目前我的项目结构是这样的:
class Test:
def __init__(self, test):
self.test= Test('fdfdf')
def tested(self, testa, testb):
return self.test(testa,testb)
没有 init .py文件。我想我需要创建一个 init .py文件,并从功能文件中指定该类的导入路径?
所以我需要了解如何在没有类定义的类中实例化另一个类,例如,如果你查看addressbook.py类,我将如何在其中实例化另一个类? kb.froglogic.com/display/KB/...
答案 0 :(得分:1)
Behave使用的导入方式略有不同,所以我做了:
from steps.test import Test
test = Test()