Bug 1338528 - [mozlog] Remove formatting of node ID to allow classes and reduce chance of duplicates. r?ahal draft
authorDave Hunt <dhunt@mozilla.com>
Fri, 10 Feb 2017 18:48:22 +0000
changeset 483074 b11abfd3f39d3eaef4618fbf4b49edac835382fd
parent 481595 25a94c1047e793ef096d8556fa3c26dd72bd37d7
child 483172 82fe85afffe97215e711140861cc3b255c0a54fe
push id45209
push userdhunt@mozilla.com
push dateMon, 13 Feb 2017 18:58:18 +0000
reviewersahal
bugs1338528
milestone54.0a1
Bug 1338528 - [mozlog] Remove formatting of node ID to allow classes and reduce chance of duplicates. r?ahal Stripping the path from the test file could cause duplicates if two files had the same name in different directories. Splitting on '::' also causes an issue when test classes are used and there are too many values to unpack. MozReview-Commit-ID: Ex5nHl3SGaQ
testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
--- a/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
+++ b/testing/mozbase/mozlog/mozlog/pytest_mozlog/plugin.py
@@ -1,14 +1,13 @@
 # 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 mozlog
-import os
 import time
 
 
 def pytest_addoption(parser):
     # We can't simply use mozlog.commandline.add_logging_group(parser) here because
     # Pytest's parser doesn't have the add_argument_group method Mozlog expects.
     group = parser.getgroup('mozlog')
 
@@ -32,21 +31,16 @@ def pytest_configure(config):
 
 
 class MozLog(object):
 
     def __init__(self):
         self.results = {}
         self.start_time = int(time.time() * 1000)  # in ms for Mozlog compatibility
 
-    def format_nodeid(self, nodeid):
-        '''Helper to Reformat/shorten a "::"-separated pytest test nodeid'''
-        testfile, testname = nodeid.split("::")
-        return " ".join([os.path.basename(testfile), testname])
-
     def pytest_configure(self, config):
         mozlog.commandline.setup_logging('pytest', config.known_args_namespace,
                                          defaults={}, allow_unused_options=True)
         self.logger = mozlog.get_default_logger(component='pytest')
 
     def pytest_sessionstart(self, session):
         '''Called before test collection; records suite start time to log later'''
         self.start_time = int(time.time() * 1000)  # in ms for Mozlog compatibility
@@ -54,17 +48,17 @@ class MozLog(object):
     def pytest_collection_modifyitems(self, items):
         '''Called after test collection is completed, just before tests are run (suite start)'''
         self.logger.suite_start(tests=items, time=self.start_time)
 
     def pytest_sessionfinish(self, session, exitstatus):
         self.logger.suite_end()
 
     def pytest_runtest_logstart(self, nodeid, location):
-        self.logger.test_start(test=self.format_nodeid(nodeid))
+        self.logger.test_start(test=nodeid)
 
     def pytest_runtest_logreport(self, report):
         '''Called 3 times per test (setup, call, teardown), indicated by report.when'''
         test = report.nodeid
         status = expected = 'PASS'
         message = stack = None
         if hasattr(report, 'wasxfail'):
             # Pytest reporting for xfail tests is somewhat counterinutitive:
@@ -84,11 +78,10 @@ class MozLog(object):
         elif report.skipped:  # indicates true skip
             status = expected = 'SKIP'
             message = report.longrepr[-1]  # here longrepr is a tuple (file, lineno, reason)
         if status != expected or expected != 'PASS':
             self.results[test] = (status, expected, message, stack)
         if report.when == 'teardown':
             defaults = ('PASS', 'PASS', None, None)
             status, expected, message, stack = self.results.get(test, defaults)
-            self.logger.test_end(test=self.format_nodeid(test),
-                                 status=status, expected=expected,
+            self.logger.test_end(test=test, status=status, expected=expected,
                                  message=message, stack=stack)