Bug 1417051 - Report relative path to Marionette test modules starting from cwd.
Only reporting the basename of the test module doesn't allow someone
to easily figure out where the file is actually located. Instead the
current working directory should be used, and the test module path
reported as relative path.
MozReview-Commit-ID: 8FdYNw4ocjL
--- a/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
+++ b/testing/marionette/harness/marionette_harness/marionette_test/testcases.py
@@ -1,13 +1,14 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import imp
+import os
import re
import sys
import time
import types
import unittest
import warnings
import weakref
@@ -219,19 +220,23 @@ class CommonTestCase(unittest.TestCase):
@classmethod
def add_tests_to_suite(cls, mod_name, filepath, suite, testloader, marionette,
fixtures, testvars, **kwargs):
"""Add all the tests in the specified file to the specified suite."""
raise NotImplementedError
@property
def test_name(self):
- return '{0}.py {1}.{2}'.format(self.__class__.__module__,
- self.__class__.__name__,
- self._testMethodName)
+ rel_path = None
+ if os.path.exists(self.filepath):
+ rel_path = self._fix_test_path(os.path.relpath(self.filepath))
+
+ return '{0} {1}.{2}'.format(rel_path,
+ self.__class__.__name__,
+ self._testMethodName)
def id(self):
# TBPL starring requires that the "test name" field of a failure message
# not differ over time. The test name to be used is passed to
# mozlog via the test id, so this is overriden to maintain
# consistency.
return self.test_name
@@ -257,16 +262,28 @@ class CommonTestCase(unittest.TestCase):
if self.marionette.session is not None:
try:
self.marionette.delete_session()
except IOError:
# Gecko has crashed?
pass
self.marionette = None
+ def _fix_test_path(self, path):
+ """Normalize a logged test path from the test package."""
+ test_path_prefixes = [
+ "tests{}".format(os.path.sep),
+ ]
+
+ for prefix in test_path_prefixes:
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+ break
+ return path
+
class MarionetteTestCase(CommonTestCase):
match_re = re.compile(r"test_(.*)\.py$")
def __init__(self, marionette_weakref, fixtures, methodName='runTest',
filepath='', **kwargs):
self.filepath = filepath
--- a/testing/marionette/harness/marionette_harness/runner/base.py
+++ b/testing/marionette/harness/marionette_harness/runner/base.py
@@ -799,21 +799,36 @@ class BaseMarionetteTestRunner(object):
raise Exception("Test file names must be of the form "
"'test_something.py'."
" Invalid test names:\n {}".format('\n '.join(invalid_tests)))
def _is_filename_valid(self, filename):
filename = os.path.basename(filename)
return self.filename_pattern.match(filename)
+ def _fix_test_path(self, path):
+ """Normalize a logged test path from the test package."""
+ test_path_prefixes = [
+ "tests{}".format(os.path.sep),
+ ]
+
+ for prefix in test_path_prefixes:
+ if path.startswith(prefix):
+ path = path[len(prefix):]
+ break
+ return path
+
def _log_skipped_tests(self):
for test in self.manifest_skipped_tests:
- name = os.path.basename(test['path'])
- self.logger.test_start(name)
- self.logger.test_end(name,
+ rel_path = None
+ if os.path.exists(test['path']):
+ rel_path = self._fix_test_path(os.path.relpath(test['path']))
+
+ self.logger.test_start(rel_path)
+ self.logger.test_end(rel_path,
'SKIP',
message=test['disabled'])
self.todo += 1
@property
def is_e10s(self):
"""Query the browser on whether E10s (Electrolysis) is enabled."""
if self.marionette is None or self.marionette.session is None:
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_marionette.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_marionette.py
@@ -15,17 +15,17 @@ class TestMarionette(MarionetteTestCase)
def test_correct_test_name(self):
"""Test that the correct test name gets set."""
expected_test_name = '{module}.py {cls}.{func}'.format(
module=__name__,
cls=self.__class__.__name__,
func=self.test_correct_test_name.__name__,
)
- self.assertEqual(self.marionette.test_name, expected_test_name)
+ self.assertIn(expected_test_name, self.marionette.test_name)
@run_if_manage_instance("Only runnable if Marionette manages the instance")
@skip_if_mobile("Bug 1322993 - Missing temporary folder")
def test_raise_for_port_non_existing_process(self):
"""Test that raise_for_port doesn't run into a timeout if instance is not running."""
self.marionette.quit()
self.assertIsNotNone(self.marionette.instance.runner.returncode)
start_time = time.time()