diff --git a/tardis/conftest.py b/tardis/conftest.py index b7a24ba0ca0..71fa42622e5 100644 --- a/tardis/conftest.py +++ b/tardis/conftest.py @@ -56,6 +56,11 @@ def pytest_addoption(parser): def pytest_configure(config): + # A common tempdir for storing plots / PDFs and other slow test related data + # generated during execution. + tempdir_session = tempfile.mkdtemp() + config.option.tempdir = tempdir_session + html_file = tempfile.NamedTemporaryFile(delete=False) # Html test report will be generated at this filepath by pytest-html plugin config.option.htmlpath = html_file.name @@ -103,6 +108,9 @@ def pytest_unconfigure(config): # is not desired, hence deleted. os.unlink(config.option.htmlpath) print "Deleted temporary file containing html report." + # Remove tempdir by recursive deletion + os.system("rm -r {0}".format(config.option.tempdir)) + # ------------------------------------------------------------------------- # hooks for influencing reporting (invoked from _pytest_terminal) diff --git a/tardis/tests/tests_slow/conftest.py b/tardis/tests/tests_slow/conftest.py index c3d78f409d9..ff5ca04c926 100644 --- a/tardis/tests/tests_slow/conftest.py +++ b/tardis/tests/tests_slow/conftest.py @@ -18,19 +18,6 @@ def data_path(): return os.path.join(os.path.dirname(os.path.realpath(__file__)), "w7") -@pytest.fixture(scope="session") -def base_plot_dir(): - githash_short = tardis.__githash__[0:7] - base_plot_dir = os.path.join("/tmp", "plots", githash_short) - - # Remove plots generated from previous runs on same githash. - if os.path.exists(base_plot_dir): - os.rmdir(base_plot_dir) - - os.makedirs(base_plot_dir) - return base_plot_dir - - @pytest.fixture(scope="session") def reference(request, reference_datadir): """ @@ -99,9 +86,9 @@ def pytest_runtest_makereport(item, call): if report.when == 'call': test_method_name = report.nodeid.split('::')[-1] if test_method_name == "test_spectrum": - # Just making it work for this commit. Will be changes subsequently - with open(os.path.join("/tmp/plots", tardis.__githash__[0:7], - "w7", "spectrum.png")) as spectrum_plot: + # "w7" written as-is. To be changed after fixture parametrization + with open(os.path.join(item.config.option.tempdir, "w7", + "spectrum.png")) as spectrum_plot: encoded_plot = base64.encodestring(spectrum_plot.read()) extra.append(pytest_html.extras.image(encoded_plot)) report.extra = extra diff --git a/tardis/tests/tests_slow/test_w7.py b/tardis/tests/tests_slow/test_w7.py index d8b720eae16..5a84036b272 100644 --- a/tardis/tests/tests_slow/test_w7.py +++ b/tardis/tests/tests_slow/test_w7.py @@ -19,7 +19,7 @@ class TestW7(object): @classmethod @pytest.fixture(scope="class", autouse=True) def setup(self, request, reference, data_path, atomic_data_fname, - reference_datadir, base_plot_dir): + reference_datadir): """ This method does initial setup of creating configuration and performing a single run of integration test. @@ -60,7 +60,7 @@ def setup(self, request, reference, data_path, atomic_data_fname, # Form a base directory to save plots for `W7` setup. # TODO: Rough prototyping, parametrize this as more setups are added. self.name = "w7" - self.base_plot_dir = os.path.join(base_plot_dir, self.name) + self.base_plot_dir = os.path.join(request.config.option.tempdir, self.name) os.makedirs(self.base_plot_dir) def test_j_estimators(self):