-
Notifications
You must be signed in to change notification settings - Fork 638
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Various tweaks can cleanups, example for #497
- Loading branch information
Showing
8 changed files
with
111 additions
and
2 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
EXAMPLE: Use Environment Variables in Steps | ||
============================================================================= | ||
|
||
:RELATED TO: `issue #497`_ | ||
|
||
This directory provides a simple example how you can use environment variables | ||
in step implementations. | ||
|
||
:: | ||
|
||
# -- USE: -f plain --no-capture (via "behave.ini" defaults) | ||
$ behave | ||
Feature: Test Environment variable concept | ||
|
||
Scenario: | ||
USE ENVIRONMENT-VAR: LOGNAME = xxx (variant 1) | ||
When I click on $LOGNAME ... passed | ||
USE ENVIRONMENT-VAR: LOGNAME = xxx (variant 2) | ||
When I use the environment variable $LOGNAME ... passed | ||
|
||
1 feature passed, 0 failed, 0 skipped | ||
1 scenario passed, 0 failed, 0 skipped | ||
2 steps passed, 0 failed, 0 skipped, 0 undefined | ||
Took 0m0.000s | ||
|
||
.. _`issue #497`: https://github.com/behave/behave/issues/497 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# ============================================================================= | ||
# BEHAVE CONFIGURATION | ||
# ============================================================================= | ||
# FILE: .behaverc, behave.ini | ||
# | ||
# SEE ALSO: | ||
# * http://packages.python.org/behave/behave.html#configuration-files | ||
# * https://github.com/behave/behave | ||
# * http://pypi.python.org/pypi/behave/ | ||
# ============================================================================= | ||
|
||
[behave] | ||
default_format = plain | ||
stdout_capture = false | ||
show_source = true |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
Feature: Test Environment variable concept | ||
|
||
Scenario: | ||
USE ENVIRONMENT-VAR: LOGNAME = xxx (variant 1) | ||
When I click on $LOGNAME ... passed | ||
USE ENVIRONMENT-VAR: LOGNAME = xxx (variant 2) | ||
When I use the environment variable $LOGNAME ... passed | ||
|
||
1 feature passed, 0 failed, 0 skipped | ||
1 scenario passed, 0 failed, 0 skipped | ||
2 steps passed, 0 failed, 0 skipped, 0 undefined | ||
Took 0m0.000s |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Feature: Test Environment variable concept | ||
|
||
Scenario: | ||
When I click on $LOGNAME | ||
When I use the environment variable $LOGNAME | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: UTF-8 -*- | ||
# -- FILE: features/steps/my_steps.py | ||
|
||
from __future__ import print_function | ||
from behave import when | ||
import os | ||
import sys | ||
|
||
# -- VARIANT 1: | ||
@when(u'I click on ${environment_variable:w}') | ||
def step_impl(context, environment_variable): | ||
env_value = os.environ.get(environment_variable, None) | ||
if env_value is None: | ||
raise LookupError("Environment variable '%s' is undefined" % environment_variable) | ||
print("USE ENVIRONMENT-VAR: %s = %s (variant 1)" % (environment_variable, env_value)) | ||
|
||
|
||
# -- VARIANT 2: Use type converter | ||
from behave import register_type | ||
import parse | ||
|
||
@parse.with_pattern(r"\$\w+") # -- ONLY FOR: $WORD | ||
def parse_environment_var(text): | ||
assert text.startswith("$") | ||
env_name = text[1:] | ||
env_value = os.environ.get(env_name, None) | ||
return (env_name, env_value) | ||
|
||
register_type(EnvironmentVar=parse_environment_var) | ||
|
||
@when(u'I use the environment variable {environment_variable:EnvironmentVar}') | ||
def step_impl(context, environment_variable): | ||
env_name, env_value = environment_variable | ||
if env_value is None: | ||
raise LookupError("Environment variable '%s' is undefined" % env_name) | ||
print("USE ENVIRONMENT-VAR: %s = %s (variant 2)" \ | ||
% (env_name, env_value)) | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
This is the new directory root for: | ||
|
||
* unit tests | ||
* functional tests (that do not use feature files) | ||
|
||
The tests here use the :pypi:`pytest` test framework for testing. | ||
|
||
.. note:: | ||
|
||
Other tests in the collocated "../test/" directory will be eventually | ||
cleaned and converted in (clean) pytests ;-) | ||
|
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