简体   繁体   中英

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.

My idea was to create the features/steps directory in any Django app that wants to use the package with the following contents:

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. 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.

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?

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"
    • 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. I like this to test that my project will run in a clean environment without any settings tied to PyCharm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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