简体   繁体   English

在 PyCharm 中为行为步骤定义指定另一个位置

[英]Specifiy another location for Behave step definitions in PyCharm

At work, we have accumulated quite some step definitions in our bigger projects that somehow overlap.在工作中,我们在更大的项目中积累了相当多的步骤定义,它们以某种方式重叠。 Hence, we decided that we want to factor out the step definitions into a separate package and use this across multiple Django apps.因此,我们决定将步骤定义分解到一个单独的包中,并在多个 Django 应用程序中使用它。

My idea was to create the features/steps directory in any Django app that wants to use the package with the following contents:我的想法是在任何想要使用包含以下内容的包的 Django 应用程序中创建features/steps目录:

from our_testing_package.steps import *

While this works with behave without a problem, we loose the convenient and great features of the BDD integration that PyCharm offers, eg autocompletion and generation of step definition from our feature file.虽然这与作品behave没有问题,我们也丧失BDD一体化的便利和巨大的功能,PyCharm优惠,例如,从我们的功能自动完成文件和生成步骤定义的。 Especially the first is crucial with this many step definitions.尤其是第一个对于这么多步骤定义至关重要。

I suppose PyCharm simply looks into each python file inside the features/steps directory and analyses the text inside them by looking for step definitions.我想 PyCharm 只是查看features/steps目录中的每个 python 文件,并通过查找步骤定义来分析其中的文本。

Is there a possibility to tell PyCharm that there is another folder with step definitions or if I have to adapt my python code in a way that PyCharm can follow the link to the external package?是否有可能告诉 PyCharm 有另一个包含步骤定义的文件夹,或者我是否必须以 PyCharm 可以遵循外部包链接的方式调整我的 Python 代码?

I usually do one of two things:我通常会做以下两件事之一:

  1. Add a custom path to the interpreter.向解释器添加自定义路径。

    • Go to File->Settings->project Interpreter转到文件->设置->项目解释器
    • In the Project-Interpreter field, click the down-facing arrow and select "Show All"在 Project-Interpreter 字段中,单击向下的箭头并选择“全部显示”
    • In that Menu, highlight your interpreter and then in the right menu, select the button "Show paths for the selected interpreter" (this is the last button)在该菜单中,突出显示您的解释器,然后在右侧菜单中,选择“显示所选解释器的路径”按钮(这是最后一个按钮)
    • click the plus symbol to add your path单击加号以添加您的路径
  2. Create a batch script that sets all my path variables and then kicks off PyCharm from the script.创建一个批处理脚本来设置我的所有路径变量,然后从脚本中启动 PyCharm。 I like this to test that my project will run in a clean environment without any settings tied to PyCharm.我喜欢用这个来测试我的项目将在一个干净的环境中运行,而没有任何与 PyCharm 相关的设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM