diff --git a/.gitignore b/.gitignore index eeb43aa306a..2e435af2f3f 100644 --- a/.gitignore +++ b/.gitignore @@ -76,5 +76,5 @@ $RECYCLE.BIN/ .pytest_cache/ sunpydata.sqlite -result_images +result_images* .pytest_cache diff --git a/sunpy/conftest.py b/sunpy/conftest.py index c881488edf8..965893726cf 100644 --- a/sunpy/conftest.py +++ b/sunpy/conftest.py @@ -14,7 +14,7 @@ matplotlib.use('Agg') from sunpy.tests.hash import HASH_LIBRARY_NAME -from sunpy.tests.helpers import new_hash_library +from sunpy.tests.helpers import new_hash_library, test_fig_dir from sunpy.extern import six import pytest @@ -49,7 +49,7 @@ def pytest_runtest_setup(item): def pytest_unconfigure(config): if len(new_hash_library) > 0: # Write the new hash library in JSON - hashfile = os.path.join('result_images', HASH_LIBRARY_NAME) + hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME) with open(hashfile, 'w') as outfile: json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': ')) diff --git a/sunpy/tests/helpers.py b/sunpy/tests/helpers.py index db430e306a7..fb1cf42d3f0 100644 --- a/sunpy/tests/helpers.py +++ b/sunpy/tests/helpers.py @@ -7,6 +7,7 @@ import tempfile import platform import os +import datetime import pytest import numpy as np @@ -52,6 +53,7 @@ def warnings_as_errors(request): hash_library = hash.hash_library new_hash_library = {} +test_fig_dir = 'result_images_{:%H%M%S}'.format(datetime.datetime.now()) def figure_test(test_function): @@ -85,9 +87,9 @@ def wrapper(*args, **kwargs): fig = plt.gcf() # Save the image that was generated - if not os.path.exists('result_images'): - os.mkdir('result_images') - result_image_loc = os.path.join('result_images', '{}.png'.format(name)) + if not os.path.exists(test_fig_dir): + os.mkdir(test_fig_dir) + result_image_loc = os.path.join(test_fig_dir, '{}.png'.format(name)) plt.savefig(result_image_loc) plt.close()