Last active
May 21, 2020 13:16
-
-
Save guewen/7579757 to your computer and use it in GitHub Desktop.
Use an optional argument in a behave phrase.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from behave.matchers import register_type | |
def parse_optional(text): | |
return text.strip() | |
# https://pypi.python.org/pypi/parse#custom-type-conversions | |
parse_optional.pattern = r'\s?\w*\s?' | |
register_type(optional=parse_optional) | |
@step(u'I find a{n:optional}{active:optional} "{model_name}" with {domain}') | |
def impl(ctx, n, active, model_name, domain): | |
assert active in ('', 'inactive', 'active', 'possibly inactive') | |
# phrases | |
# Given I find a "res.users" with login: test | |
# Given I find an inactive "res.users" with login: test | |
# Given I find an active "res.users" with login: test | |
# Given I find a possibly inactive "res.users" with login: test |
@huyenuet I guess you are using pycharm. One issue I am facing when using optional part is steps are passing but I am not able to navigate to the steps as they are showing as undefined. Are you facing this issue ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I switch domain2_browser to 1st position, and it works!
e.g.
def impl(ctx, domain2_browser, state):