Commits

Mikhail Korobov committed c90ab44

Convert fabric's abort() calls to FabricAbortException so it can be catched by unittests

  • Participants
  • Parent commits b4b3cc4

Comments (0)

Files changed (2)

fabtest/__init__.py

 from fabtest.test import VirtualBoxTest, FabTest
-from fabtest.utils import fab
+from fabtest.utils import fab, FabricAbortException
 from fabtest.vbox import VirtualBox
 from fabric.main import get_hosts
 from fabric.network import interpret_host_string, HostConnectionCache
 
+class FabricAbortException(Exception):
+    pass
+
 def fab(command, *args, **kwargs):
     """ Runs fab command. Accepts callable. """
 
     # partially implement the logic from fabric.main.main
     state.env.command = command.__name__
     state.env.all_hosts = hosts = get_hosts(command, None, None)
-    for host in hosts:
-        interpret_host_string(host)
-        res = command(*args, **kwargs)
-        results.append(res)
-    return results
+
+    try: # convert fabric.abort() calls to real exceptions
+        for host in hosts:
+            interpret_host_string(host)
+            res = command(*args, **kwargs)
+            results.append(res)
+        return results
+    except SystemExit, e:
+        import traceback
+        traceback.print_exc()
+        raise FabricAbortException()
+