从 Python radish-bdd 可执行文件导入模块失败
Import module fails from the Python radish-bdd executable
我正在尝试 运行 在 Radish 中进行测试,Radish 是 Python 的行为驱动开发环境,但我连最简单的事情都做不到。
我有这个结构:
.
├── features
│ └── my.feature
└── radish
├── __init__.py
├── harness
│ ├── __init__.py
│ └── main.py
└── steps.py
当我做
python -c "import radish.harness"
从我的工作目录“.”,一切正常。
当我在文件 steps.py 中执行相同操作("import radish.harness" 或 "import harness")时,我在从同一目录调用命令 "radish features" 时得到了这个:
ModuleNotFoundError: No module named 'radish.harness'
或
ModuleNotFoundError: No module named 'harness'
Radish-bdd 快速入门指南 quick start guide 是这样说的:
How does radish find my python modules? radish imports all python
modules inside the basedir. Per default the basedir points to
$PWD/radish which in our case is perfectly fine.
确实会自动导入 radish 目录中的文件,但我无法从这些文件中导入任何内容(系统库除外)。
谁能告诉我如何导入模块?我迷路了。看来我的 python 模块导入知识没有帮助。
我建议您将 'harness' 目录移动到与 'features' 和 'radish' 目录相同的级别。
.
├── features
│ └── my.feature
├── radish
│ ├── __init__.py
│ └── steps.py
└── harness
├── __init__.py
└── main.py
如果你从你的工作目录 (".") 像这样调用萝卜:
radish -b radish features/my.feature
然后您可以像这样从 steps.py 导入 "harness" 模块
import harness
这会起作用,因为在这种情况下 Python 会在当前目录中找到您的 "harness" 模块。
我正在尝试 运行 在 Radish 中进行测试,Radish 是 Python 的行为驱动开发环境,但我连最简单的事情都做不到。
我有这个结构:
.
├── features
│ └── my.feature
└── radish
├── __init__.py
├── harness
│ ├── __init__.py
│ └── main.py
└── steps.py
当我做
python -c "import radish.harness"
从我的工作目录“.”,一切正常。
当我在文件 steps.py 中执行相同操作("import radish.harness" 或 "import harness")时,我在从同一目录调用命令 "radish features" 时得到了这个:
ModuleNotFoundError: No module named 'radish.harness'
或
ModuleNotFoundError: No module named 'harness'
Radish-bdd 快速入门指南 quick start guide 是这样说的:
How does radish find my python modules? radish imports all python modules inside the basedir. Per default the basedir points to $PWD/radish which in our case is perfectly fine.
确实会自动导入 radish 目录中的文件,但我无法从这些文件中导入任何内容(系统库除外)。
谁能告诉我如何导入模块?我迷路了。看来我的 python 模块导入知识没有帮助。
我建议您将 'harness' 目录移动到与 'features' 和 'radish' 目录相同的级别。
.
├── features
│ └── my.feature
├── radish
│ ├── __init__.py
│ └── steps.py
└── harness
├── __init__.py
└── main.py
如果你从你的工作目录 (".") 像这样调用萝卜:
radish -b radish features/my.feature
然后您可以像这样从 steps.py 导入 "harness" 模块
import harness
这会起作用,因为在这种情况下 Python 会在当前目录中找到您的 "harness" 模块。