Bug 1062518 - ensure that |mach python-test| considers $PWD when finding tests; r=mshal
authorNathan Froyd <froydnj@mozilla.com>
Mon, 15 Sep 2014 13:25:41 -0400
changeset 205830 d3333ee247393770ec290abb07faa378d7e9206d
parent 205829 6cbb53223442de7ddbaf84c835717749c7192cfb
child 205831 a30de23be927e5a68425ece9b5a940f7f579f569
push id27503
push userryanvm@gmail.com
push dateWed, 17 Sep 2014 18:42:22 +0000
treeherdermozilla-central@d2c01d77b9d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs1062518
milestone35.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1062518 - ensure that |mach python-test| considers $PWD when finding tests; r=mshal
python/mach_commands.py
--- a/python/mach_commands.py
+++ b/python/mach_commands.py
@@ -58,30 +58,42 @@ class MachCommands(MachCommandBase):
 
         # Python's unittest, and in particular discover, has problems with
         # clashing namespaces when importing multiple test modules. What follows
         # is a simple way to keep environments separate, at the price of
         # launching Python multiple times. This also runs tests via mozunit,
         # which produces output in the format Mozilla infrastructure expects.
         return_code = 0
         files = []
-        for test in [mozpack.path.join(self.topsrcdir, t) for t in tests]:
-            if test.endswith('.py') and os.path.isfile(test):
-                files.append(test)
-            elif os.path.isfile(test + '.py'):
-                files.append(test + '.py')
-            elif os.path.isdir(test):
-                files += glob.glob(mozpack.path.join(test, 'test*.py'))
-                files += glob.glob(mozpack.path.join(test, 'unit*.py'))
-            else:
-                self.log(logging.WARN, 'python-test',
-                         {'test': mozpack.path.relpath(test, self.topsrcdir)},
-                         'TEST-UNEXPECTED-FAIL | Invalid test: {test}')
-                if stop:
-                    return 1
+        # We search for files in both the current directory (for people running
+        # from topsrcdir or cd'd into their test directory) and topsrcdir (to
+        # support people running mach from the objdir).  The |break|s in the
+        # loop below ensure that we don't run tests twice if we're running mach
+        # from topsrcdir
+        search_dirs = ['.', self.topsrcdir]
+        last_search_dir = search_dirs[-1]
+        for t in tests:
+            for d in search_dirs:
+                test = mozpack.path.join(d, t)
+                if test.endswith('.py') and os.path.isfile(test):
+                    files.append(test)
+                    break
+                elif os.path.isfile(test + '.py'):
+                    files.append(test + '.py')
+                    break
+                elif os.path.isdir(test):
+                    files += glob.glob(mozpack.path.join(test, 'test*.py'))
+                    files += glob.glob(mozpack.path.join(test, 'unit*.py'))
+                    break
+                elif d == last_search_dir:
+                    self.log(logging.WARN, 'python-test',
+                             {'test': t},
+                             'TEST-UNEXPECTED-FAIL | Invalid test: {test}')
+                    if stop:
+                        return 1
 
         for f in files:
             file_displayed_test = [] # Used as a boolean.
             def _line_handler(line):
                 if not file_displayed_test and line.startswith('TEST-'):
                     file_displayed_test.append(True)
 
             inner_return_code = self.run_process(