Skip to content

Commit

Permalink
Merge pull request #2195 from SFDO-Tooling/feature/robot_cross-projec…
Browse files Browse the repository at this point in the history
…t-tests

Feature/robot cross project tests
  • Loading branch information
boakley authored Nov 26, 2020
2 parents ac78480 + a6a4bf0 commit 656d663
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
20 changes: 19 additions & 1 deletion cumulusci/tasks/robotframework/robotframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def _init_options(self, kwargs):
)

listeners = self.options["options"].setdefault("listener", [])

if process_bool_arg(self.options.get("verbose") or False):
listeners.append(KeywordLogger())

Expand Down Expand Up @@ -164,13 +165,30 @@ def _run_task(self):
num_failed = result.returncode

else:
# Save it so that we can restore it later
orig_sys_path = sys.path.copy()

# Add each source to PYTHONPATH. Robot recommends that we
# use pythonpathsetter instead of directly setting
# sys.path. <shrug>
for path in source_paths.values():
pythonpathsetter.add_path(path, end=True)

num_failed = robot_run(*self.options["suites"], **options)
# Make sure the path to the repo root is on sys.path. Normally
# it will be, but if we're running this task from another repo
# it might not be.
#
# Note: we can't just set the pythonpath option; that
# option is specifically called out as not being supported
# by robot.run. Plus, robot recommends we call a special
# function instead of directly modifying sys.path
if self.project_config.repo_root not in sys.path:
pythonpathsetter.add_path(self.project_config.repo_root)

try:
num_failed = robot_run(*self.options["suites"], **options)
finally:
sys.path = orig_sys_path

# These numbers are from the robot framework user guide:
# http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#return-codes
Expand Down
45 changes: 39 additions & 6 deletions cumulusci/tasks/robotframework/tests/test_robotframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from cumulusci.tasks.salesforce.tests.util import create_task
from cumulusci.tasks.robotframework.debugger import DebugListener
from cumulusci.tasks.robotframework.robotframework import KeywordLogger
from cumulusci.utils import touch
from cumulusci.utils import touch, temporary_dir


from cumulusci.tasks.robotframework.libdoc import KeywordFile

Expand Down Expand Up @@ -209,7 +210,10 @@ def test_user_defined_listeners_option(self):
self.assertIn(KeywordLogger, listener_classes)

@mock.patch("cumulusci.tasks.robotframework.robotframework.robot_run")
def test_sources(self, mock_robot_run):
@mock.patch(
"cumulusci.tasks.robotframework.robotframework.pythonpathsetter.add_path"
)
def test_sources(self, mock_add_path, mock_robot_run):
"""Verify that sources get added to PYTHONPATH when task runs"""
universal_config = UniversalConfig()
project_config = BaseProjectConfig(
Expand Down Expand Up @@ -237,14 +241,43 @@ def test_sources(self, mock_robot_run):
)

mock_robot_run.return_value = 0
self.assertFalse("dummy1" in sys.path)
self.assertFalse("dummy2" in sys.path)
self.assertNotIn("dummy1", sys.path)
self.assertNotIn("dummy2", sys.path)
task()
project_config.get_namespace.assert_has_calls(
[mock.call("test1"), mock.call("test2")]
)
self.assertTrue("dummy1" in sys.path)
self.assertTrue("dummy2" in sys.path)
mock_add_path.assert_has_calls(
[mock.call("dummy1", end=True), mock.call("dummy2", end=True)]
)
self.assertNotIn("dummy1", sys.path)
self.assertNotIn("dummy2", sys.path)

@mock.patch("cumulusci.tasks.robotframework.robotframework.robot_run")
@mock.patch(
"cumulusci.tasks.robotframework.robotframework.pythonpathsetter.add_path"
)
def test_repo_root_in_sys_path(self, mock_add_path, mock_robot_run):
"""Verify that the repo root is added to sys.path
Normally, the repo root is added to sys.path in the __init__
of BaseSalesforceTask. However, if we're running a task from
another repo, the git root of that other repo isn't added. The
robot task will do that; this verifies that.
"""
mock_robot_run.return_value = 0
universal_config = UniversalConfig()
project_config = BaseProjectConfig(universal_config)
with temporary_dir() as d:
project_config.repo_info["root"] = d
task = create_task(
Robot, {"suites": "tests"}, project_config=project_config
)
self.assertNotIn(d, sys.path)
task()
mock_add_path.assert_called_once_with(d)
self.assertNotIn(d, sys.path)

@mock.patch("cumulusci.tasks.robotframework.robotframework.robot_run")
def test_sources_not_found(self, mock_robot_run):
Expand Down

0 comments on commit 656d663

Please sign in to comment.