简体   繁体   中英

Developing behave steps with PyDev

Behave is a great tool for behavior driven development in Python. However, in combination with PyDev I've got two Problems:

  1. PyDev can't resolve behave's @given , @when and @then annotations. This probably happens because behave does some name magic the behave package.
  2. behave suggests to name all methods step as every method has an annotation which defines the "real" name. PyDev complains about these "duplicate" methods.

    Example:

     from behave import given, when, then @given('I navigate to Google') def step(context): # ... @when('I enter coffee into the search field') def step(context): # ... 

By now, I work around both Problems by including #@PydevCodeAnalysisIgnore , which turns off any PyDev analysis. I'd like to keep PyDev analysis for all other parts of the code.

Any suggestions how to solve this?

  1. Just a guess. Have You tried with import redefinitions?

     from behave import given as given_behaviour, when as when_behaviour, then as then_behaviour @given_behaviour('I navigate to Google') 

    You can also check the eclipse settings: menu Window -> Preferences -> PyDev -> Interpreters -> Python Interpreters. Sometimes it might help to remove and re-add the python interpreter if new libraries has been added after that the interpreter was configured in order to include those in the System PYTHONPATH in eclipse.

  2. Try adding #@ followed by the message in camel case to the end of the method name to turn off the warning message in PyDev. Something like:

     def step(context): #@DuplicatedSignature 

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