Skip to content

Commit

Permalink
Use tempdir per session to store plots of slow tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Karan Desai committed Jun 3, 2016
1 parent d564bdd commit 02eaa21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
8 changes: 8 additions & 0 deletions tardis/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 3 additions & 16 deletions tardis/tests/tests_slow/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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
4 changes: 2 additions & 2 deletions tardis/tests/tests_slow/test_w7.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 02eaa21

Please sign in to comment.