Add "self.env" for handling test environments

This commit is contained in:
Michael Mintz 2018-08-10 00:06:01 -04:00
parent 31494647e5
commit 88de946587
3 changed files with 17 additions and 5 deletions

View File

@ -70,6 +70,7 @@ class BaseCase(unittest.TestCase):
super(BaseCase, self).__init__(*args, **kwargs)
self.driver = None
self.environment = None
self.env = None # Add a shortened version of self.environment
self.__last_url_of_delayed_assert = "data:,"
self.__last_page_load_url = "data:,"
self.__page_check_count = 0
@ -2754,6 +2755,8 @@ class BaseCase(unittest.TestCase):
test_id = "%s.%s.%s" % (self.__class__.__module__,
self.__class__.__name__,
self._testMethodName)
self.environment = pytest.config.option.environment
self.env = self.environment # Add a shortened version
self.with_selenium = pytest.config.option.with_selenium
self.headless = pytest.config.option.headless
self.headless_active = False

View File

@ -4,6 +4,7 @@ This class containts some frequently-used constants
class Environment:
# Usage Example => "--env=qa" => Then access value in tests with "self.env"
QA = "qa"
STAGING = "staging"
PRODUCTION = "production"

View File

@ -17,11 +17,18 @@ from seleniumbase.fixtures import constants, errors
class Base(Plugin):
"""
The base_plugin includes the following variables:
self.options.env -- the environment for the tests to use (--env=ENV)
self.options.data -- any extra data to pass to the tests (--data=DATA)
self.options.log_path -- the directory in which the log files
are saved (--log_path=LOG_PATH)
The base_plugin includes the following variables for nosetest runs:
self.env -- The environment for the tests to use (Usage: --env=ENV)
self.data -- Any extra data to pass to the tests (Usage: --data=DATA)
self.log_path -- The directory where log files get saved to
(Usage: --log_path=LOG_PATH)
self.report -- The option to create a fancy report after tests complete
(Usage: --report)
self.show_report -- If self.report is turned on, then the report will
display immediately after tests complete their run.
Only use this when running tests locally, as this will
pause the test run until the report window is closed.
(Usage: --show_report)
"""
name = 'testing_base' # Usage: --with-testing_base
@ -90,6 +97,7 @@ class Base(Plugin):
if not os.path.exists(test_logpath):
os.makedirs(test_logpath)
test.test.environment = self.options.environment
test.test.env = self.options.environment # Add a shortened version
test.test.data = self.options.data
test.test.args = self.options
self.test_count += 1