Bug 1340092 - [mozlog] Add metadata from pytest-metadata plugin if installed to suite_start. r=ahal
authorDave Hunt <dhunt@mozilla.com>
Thu, 16 Feb 2017 01:54:25 +0000
changeset 485680 9b09b5b2f7292b89dfd204f15dae6f8ebef94196
parent 485679 b854735013bbbd22e800e4a6c4031475be7ff110
child 485681 51541cde2e0643f6441eecd7d9deec828624257d
push id45811
push userbmo:markh@mozilla.com
push dateFri, 17 Feb 2017 01:50:29 +0000
reviewersahal
bugs1340092
milestone54.0a1
Bug 1340092 - [mozlog] Add metadata from pytest-metadata plugin if installed to suite_start. r=ahal If the optional pytest-metadata plugin is installed, add the metadata as run_info when logging the suite_start to give additional context to the results. MozReview-Commit-ID: 1MeXZTmzvyp
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
@@ -36,27 +36,31 @@ class MozLog(object):
         self._started = False
         self.results = {}
         self.start_time = int(time.time() * 1000)  # in ms for Mozlog compatibility
 
     def _log_suite_start(self, tests):
         if not self._started:
             # As this is called for each node when using pytest-xdist, we want
             # to avoid logging multiple suite_start messages.
-            self.logger.suite_start(tests=tests, time=self.start_time)
+            self.logger.suite_start(
+                tests=tests,
+                time=self.start_time,
+                run_info=self.run_info)
             self._started = True
 
     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
+        self.run_info = getattr(session.config, '_metadata', None)
 
     def pytest_collection_finish(self, session):
         '''Called after test collection is completed, just before tests are run (suite start)'''
         self._log_suite_start([item.nodeid for item in session.items])
 
     def pytest_xdist_node_collection_finished(self, node, ids):
         '''Called after each pytest-xdist node collection is completed'''
         self._log_suite_start(ids)