No need to kill mdk behat after tests
authorFred <fmcell@gmail.com>
Tue, 19 Feb 2013 06:08:55 +0000 (14:08 +0800)
committerFred <fmcell@gmail.com>
Tue, 19 Feb 2013 06:08:55 +0000 (14:08 +0800)
lib/tools.py
moodle-behat.py

index 15d69ec..f50b2dc 100644 (file)
@@ -117,12 +117,26 @@ def stableBranch(version):
 class ProcessInThread(threading.Thread):
     """Executes a process in a separate thread"""
 
-    cli = None
-    loop = True
+    cmd = None
+    cwd = None
+    stdout = None
+    stderr = None
+    _kill = False
 
-    def __init__(self, cli):
+    def __init__(self, cmd, cwd=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
         threading.Thread.__init__(self)
-        self.cli = cli
+        if type(cmd) != 'list':
+            cmd = shlex.split(str(cmd))
+        self.cmd = cmd
+        self.cwd = None
+        self.stdout = stdout
+        self.stderr = stderr
+
+    def kill(self):
+        self._kill = True
 
     def run(self):
-        process(self.cli)
+        proc = subprocess.Popen(self.cmd, cwd=self.cwd, stdout=self.stdout, stderr=self.stderr)
+        while proc.poll():
+            if self._kill:
+                proc.kill()
index c6de9c1..edca598 100755 (executable)
@@ -114,11 +114,24 @@ try:
             seleniumServer.start()
 
         debug('Running Behat tests')
+
         # Sleep for a few seconds before starting Behat
         if phpServer or seleniumServer:
             sleep(3)
 
+        # Running the tests
         process(cmd, M.path, None, None)
+
+        # Kill the remaining processes
+        if phpServer:
+            phpServer.kill()
+        if seleniumServer:
+            seleniumServer.kill()
+
+        # Remove the switch completely tag
+        if M.get('behat_switchcompletely'):
+            M.updateConfig('behat_switchcompletely', False)
+
     else:
         debug('Behat command: %s' % (cmd))