Behat command outputs more information to the extra directory
authorFrederic Massart <fred@moodle.com>
Wed, 5 Nov 2014 02:58:24 +0000 (10:58 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 5 Nov 2014 02:58:24 +0000 (10:58 +0800)
mdk/commands/behat.py
mdk/moodle.py

index 7d60ef3..b2ee316 100644 (file)
@@ -88,6 +88,14 @@ class BehatCommand(Command):
             }
         ),
         (
+            ['-D', '--no-dump'],
+            {
+                'action': 'store_false',
+                'dest': 'faildump',
+                'help': 'use the standard command without fancy screenshots or output to a directory'
+            }
+        ),
+        (
             ['-s', '--switch-completely'],
             {
                 'action': 'store_true',
@@ -209,8 +217,11 @@ class BehatCommand(Command):
             else:
                 prefix = None
 
+            outputDir = self.Wp.getExtraDir(M.get('identifier'), 'behat')
+            outpurUrl = self.Wp.getUrl(M.get('identifier'), extra='behat')
+
             logging.info('Initialising Behat, please be patient!')
-            M.initBehat(switchcompletely=args.switchcompletely, force=args.force, prefix=prefix)
+            M.initBehat(switchcompletely=args.switchcompletely, force=args.force, prefix=prefix, faildumppath=outputDir)
             logging.info('Behat ready!')
 
             # Preparing Behat command
@@ -224,6 +235,10 @@ class BehatCommand(Command):
             if not (args.tags or args.testname) and nojavascript:
                 cmd.append('--tags ~@javascript')
 
+            if args.faildump:
+                cmd.append('--format="progress,progress,html,failed"')
+                cmd.append('--out=",{0}/progress.txt,{0}/status.html,{0}/failed.txt"'.format(outputDir))
+
             cmd.append('--config=%s/behat/behat.yml' % (M.get('behat_dataroot')))
 
             # Checking feature argument
@@ -286,6 +301,8 @@ class BehatCommand(Command):
 
                 # Running the tests
                 try:
+                    if args.faildump:
+                        logging.info('More output can be found at:\n %s\n %s', outputDir, outpurUrl)
                     process(cmd, M.path, None, None)
                 except KeyboardInterrupt:
                     pass
@@ -301,6 +318,8 @@ class BehatCommand(Command):
                     self.disable(M)
 
             else:
+                if args.faildump:
+                    logging.info('More output will be accessible at:\n %s\n %s', outputDir, outpurUrl)
                 if olderThan26:
                     logging.info('Launch PHP Server (or set $CFG->behat_switchcompletely to True):\n %s' % (phpCommand))
                 if seleniumCommand:
index 1acc7b2..a9548ea 100644 (file)
@@ -285,7 +285,7 @@ class Moodle(object):
         """Initialise the PHPUnit environment"""
         raise Exception('This method is deprecated, use phpunit.PHPUnit.init() instead.')
 
-    def initBehat(self, switchcompletely=False, force=False, prefix=None):
+    def initBehat(self, switchcompletely=False, force=False, prefix=None, faildumppath=None):
         """Initialise the Behat environment"""
 
         if self.branch_compare(25, '<'):
@@ -304,6 +304,13 @@ class Moodle(object):
         currentPrefix = self.get('behat_prefix')
         behat_prefix = prefix or 'zbehat_'
 
+        # Set behat_faildump_path
+        currentFailDumpPath = self.get('behat_faildump_path')
+        if faildumppath and currentFailDumpPath != faildumppath:
+            self.updateConfig('behat_faildump_path', faildumppath)
+        else:
+            self.removeConfig('behat_faildump_path')
+
         if not currentPrefix or force:
             self.updateConfig('behat_prefix', behat_prefix)
         elif currentPrefix != behat_prefix and self.get('dbtype') != 'oci':