From 18e2f3703521f1fb8e7f205d46532582611ad18c Mon Sep 17 00:00:00 2001 From: Karan Desai Date: Thu, 16 Jun 2016 20:11:40 +0530 Subject: [PATCH] Embed plot thumbnails in report through extras.html --- tardis/tests/tests_slow/conftest.py | 10 ++++----- tardis/tests/tests_slow/plot_helpers.py | 29 +++++++++++++++---------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/tardis/tests/tests_slow/conftest.py b/tardis/tests/tests_slow/conftest.py index d6b0fa5ad33..cbbf4d537c7 100644 --- a/tardis/tests/tests_slow/conftest.py +++ b/tardis/tests/tests_slow/conftest.py @@ -48,17 +48,15 @@ def pytest_runtest_makereport(item, call): if report.when == "call": if "plot_object" in item.fixturenames: - report.extra = item.funcargs["plot_object"].get_extras() + plot_obj = item.funcargs["plot_object"] + plot_obj.upload() + report.extra = plot_obj.get_extras() @pytest.fixture(scope="function") def plot_object(request): - plot_obj = PlotUploader() + plot_obj = PlotUploader(request) setattr(request.node, "plot_obj", plot_obj) - - def fin(): - plot_obj.upload(request) - request.addfinalizer(fin) return plot_obj diff --git a/tardis/tests/tests_slow/plot_helpers.py b/tardis/tests/tests_slow/plot_helpers.py index b8e3bab1727..86eb368973f 100644 --- a/tardis/tests/tests_slow/plot_helpers.py +++ b/tardis/tests/tests_slow/plot_helpers.py @@ -1,12 +1,15 @@ import tempfile + from pytest_html import extras import tardis class PlotUploader(object): - def __init__(self): + def __init__(self, request): + self.request = request self._plots = list() - self.plot_links = list() + self.plot_html = list() + self.dokuwiki_url = self.request.config.dokureport.dokuwiki_url def add(self, plot, name): """ @@ -14,25 +17,29 @@ def add(self, plot, name): """ self._plots.append((plot, name)) - def upload(self, request): + def upload(self): """ Upload the content in self._plots to dokuwiki. """ - dokuwiki_url = request.config.dokureport.dokuwiki_url for plot, name in self._plots: plot_file = tempfile.NamedTemporaryFile(suffix=".png") plot.savefig(plot_file.name) - request.config.dokureport.doku_conn.medias.add( + self.request.config.dokureport.doku_conn.medias.add( "plots:{0}_{1}.png".format(tardis.__githash__[0:7], name), plot_file.name ) - self.plot_links.append(extras.url( - "{0}lib/exe/fetch.php?media=plots:{1}_{2}.png".format( - dokuwiki_url, tardis.__githash__[0:7], name - ), name) - ) + + thumbnail_html = """ +
+ + + +
+ """.format(self.dokuwiki_url, tardis.__githash__[0:7], name) + + self.plot_html.append(extras.html(thumbnail_html)) plot_file.close() def get_extras(self): - return self.plot_links + return self.plot_html