我试图调试为什么我的一个pytest失败,并且我在pytest中使用了python3.7的breakpoint()。我有以下代码:
(Pdb) train_df
Acquisition_personal_win_amount ... yrs_since_earliest_degree
0 -5 ... -5
1 -5 ... -5
2 -5 ... -5
3 -5 ... -5
4 -5 ... -5
5 -5 ... -5
6 -5 ... -5
[7 rows x 488 columns]
(Pdb) len(train_df.columns.values)
488
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in train_df.columns.values})
*** NameError: name 'train_df' is not defined
请注意,实际上已经定义了train_df
!使用列表推导会干扰pdb检测train_df存在吗?也许是pytest修补某些变量的问题?
当我尝试使用train_df.columns.values时,会发生相同的问题
(Pdb) len(train_df.columns.values)
488
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in train_df.columns.values})
*** NameError: name 'train_df' is not defined
(Pdb) train_df = train_df.assign(**{feat_name: -1 for feat_name in allowed_col_names if feat_name not in [1,2,3]})
(Pdb)
请注意,切换到简单数组[1,2,3]
不会产生任何问题!