【问题标题】:Running feature files python behave - Pyhcharm - No Feature found运行功能文件 python 行为 - Pyhcharm - 未找到功能
【发布时间】:2019-08-01 18:05:59
【问题描述】:

我在运行我的一个功能文件时遇到问题。我可以运行其中一个,但不能运行另一个。我对两者的运行配置都有完全相同的设置。

raise ParserError(msg, None, self.filename)
behave.parser.ParserError: Failed to parse "C:\project\test.feature": 
Parser failure in state init, at line 1
REASON: No feature found.

如果我改变我得到的配置:

"C:\Program Files (x86)\Python\pythonw.exe" -m behave "C:\Program Files (x86)\JetBrains\PyCharm 2017.1\helpers\pycharm\behave_runner.py"
Testing started at 16:41 ...
ConfigError: No steps directory in "C:\Program Files (x86)\JetBrains\PyCharm 2017.1\helpers\pycharm"

【问题讨论】:

  • 我在功能文件夹的终端中运行它们,只需使用命令行为。不是黄瓜,是黄瓜。 Steps 位于名为 steps 的文件夹中,我正在使用 python

标签: python bdd gherkin python-behave


【解决方案1】:

问题可能是文件编码。 Behave 似乎不能很好地处理带有 BOM 的 utf-8 文件。 对我来说,移除炸弹是有效的。在 Pycharm 中,转到 File -> Remove BOM

【讨论】:

    【解决方案2】:
    behave.parser.ParserError: Failed to parse "C:\project\test.feature": 
    Parser failure in state init, at line 1
    REASON: No feature found.
    

    您似乎错过了在小黄瓜文件的Feature 部分添加功能名称。

    你的test.feature 文件结构应该是这样的:

    Feature: feature name
    
      Scenario: some scenario
          Given some condition
           Then some result is expected.
    

    我只是使用命令行为在 features 文件夹中的终端中运行它们。不是黄瓜,是黄瓜。 Steps 位于名为 steps 的文件夹中,我正在使用 python

    确保您的项目具有正确的behave directory structure:

    features/
    features/everything.feature
    features/steps/
    features/steps/steps.py
    

    尝试从外部功能文件夹运行您的脚本:

    behave features/everything.feature
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-16
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-05
      相关资源
      最近更新 更多