Skip to main content
 首页 » 编程设计

python之如何从其他模块导入生菜步骤

2025年05月04日8lexus

我想分享生菜不同特征之间的一些步骤。将它们放在某个模块中,然后在步骤定义之前导入该模块,根本行不通。我收到未定义步骤的消息。

有没有什么直接的方法可以在生菜的不同特征之间共享步骤定义?

请您参考如下方法:

像这样创建目录结构:

root: 
    __init__.py 
    features: 
        __init__.py 
        steps.py: # global steps 
        some_features: 
            __init__.py 
            file.feature 
            steps.py # specific steps  

在 root/features/steps.py 和 root/features/some_features 中定义全局步骤

执行:from root.features.steps import *

意思是:some_features的步骤是some_features/steps.py