将pytest灯具列表转换为参数化灯具

时间:2016-06-07 02:18:05

标签: python pytest

假设我有一个处理frobs的包,一个frob是一些任意对象,内部细节并不重要,它们来自不同的类型,我将用颜色表示。我有一堆固定装置可以返回不同的颜色,蓝色,绿色等等。有些测试只适用于特定的颜色(这就是为什么它们是独立的灯具),而其他的则适用于任何frob,所以我想测试所有我的frob灯具。我想编写一个夹具创建器,它获取frobs的夹具列表,并生成一个在不同的frobs上参数化的夹具,假设frob夹具可​​能有不同的参数并依赖于其他夹具。

我想做的一个例子是:

int[] attrs = {R.attr.txtColor} ;
try { //getPackageManager() can throw an exeption
    Activity activity = getActivity();
    themeId = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).theme;
    TypedArray ta = activity.obtainStyledAttributes(themeId, attrs);
    int color = ta.getColor(0, Color.BLACK); //I set Black as the default color
    txtView.setTextColor(color);
    ta.recycle();
} catch (NameNotFoundException e) {
    e.printStackTrace();
}

然后能够在我的测试中使用frobs夹具。

0 个答案:

没有答案
相关问题