在Pycharm下运行行为不起作用,但在bash命令行下运行相同行为

时间:2019-06-27 10:53:17

标签: python pycharm python-behave

我有一个很烦人的问题,我无法解释(也无法解决:)在Pycharm(版本2018.1,内部版本#PY-181.4203.547)下运行行为测试。

我已经定义了如下的Behave运行配置:

enter image description here

除了行为版本(即1.2.6)之外,virtualenv中没有其他特殊内容:

(sanitycheck)$ pip freeze | grep behave
behave==1.2.6

如果我从pycharm运行测试以启动上述配置,则会收到错误消息:

Testing started at 12:37 ...
/home/fermin/src/virtualenvs/sanitycheck/bin/python2.7 /data/apps/pycharm-2017.3.4/helpers/pycharm/behave_runner.py
Supplied path: "/home/fermin/src/iotp-pqa/tests/features/TS04_pepflows/026_pep2cbv2_httpsnotifications.feature"
Primary path is to a file so using its directory
Trying base directory: /home/fermin/src/iotp-pqa/tests/features/TS04_pepflows
Trying base directory: /home/fermin/src/iotp-pqa/tests/features
Trying base directory: /home/fermin/src/iotp-pqa/tests
Traceback (most recent call last):
  File "/data/apps/pycharm-2017.3.4/helpers/pycharm/behave_runner.py", line 328, in <module>
    _BehaveRunner(my_config, base_dir, use_old_runner).run()
  File "/data/apps/pycharm-2017.3.4/helpers/pycharm/_bdd_utils.py", line 102, in run
    number_of_tests = self._get_number_of_tests()
  File "/data/apps/pycharm-2017.3.4/helpers/pycharm/_bdd_utils.py", line 221, in _get_number_of_tests
    for feature in self._get_features_to_run():
  File "/data/apps/pycharm-2017.3.4/helpers/pycharm/behave_runner.py", line 236, in _get_features_to_run
    self.__real_runner.run()
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/runner.py", line 804, in run
    return self.run_with_paths()
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/runner.py", line 809, in run_with_paths
    self.load_step_definitions()
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/runner.py", line 796, in load_step_definitions
    load_step_modules(step_paths)
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/runner_util.py", line 412, in load_step_modules
    exec_file(os.path.join(path, name), step_module_globals)
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/runner_util.py", line 386, in exec_file
    exec(code, globals_, locals_)
  File "../../../home/fermin/src/iotp-pqa/tests/steps/cep_steps.py", line 34, in <module>
    @step(u'I create a rule on id')
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/step_registry.py", line 92, in wrapper
    self.add_step_definition(step_type, step_text, func)
  File "/home/fermin/src/virtualenvs/sanitycheck/local/lib/python2.7/site-packages/behave/step_registry.py", line 58, in add_step_definition
    raise AmbiguousStep(message % (new_step, existing_step))
behave.step_registry.AmbiguousStep: @step('I create a rule on id') has already been defined in
  existing step @step('I create a rule on id') at tests/steps/cep_steps.py:34

Process finished with exit code 1

也就是有关重复步骤定义的问题。但是,该步骤没有重复,实际上,如果我按如下所示从命令行运行上述测试,那么它将起作用。

(sanitycheck)$ behave tests/features/TS04_pepflows/026_pep2cbv2_httpsnotifications.feature
...
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
12 steps passed, 1 failed, 3 skipped, 0 undefined
Took 0m21.965s

(预计测试将失败,“ 1失败”是可以的)

此外,如果我从bash命令行运行Pycharm运行的相同命令(以上日志中的第一行:/home/fermin/src/virtualenvs/sanitycheck/bin/python2.7 /data/apps/pycharm-2017.3.4/helpers/pycharm/behave_runner.py),则它可以工作(尽管在这种情况下,它不仅执行.feature,而且还执行所有测试)我想要)。

有人遇到过同样的情况吗?关于为什么它可以从bash命令行运行但在Pycharm下不起作用的任何想法吗?如何解决这个问题?

谢谢!

0 个答案:

没有答案