Add decorator to test parallel execution of unit test

This commit is contained in:
Johannes Schönberger
2015-05-19 17:57:47 -07:00
parent 4b0456b8ef
commit 574159f724
2 changed files with 34 additions and 1 deletions
+33
View File
@@ -3,6 +3,8 @@
import os
import re
import threading
import functools
from tempfile import NamedTemporaryFile
from numpy import testing
@@ -201,6 +203,37 @@ def teardown_test():
warnings.simplefilter('default')
def test_parallel(num_threads=2):
"""Decorator to run the same function multiple times in parallel.
Parameters
----------
num_threads : int, optional
The number of times the function is run in parallel.
Notes
-----
This decorator does not pass the return value of the decorated function.
"""
assert num_threads > 0
def wrapper(func):
@functools.wraps(func)
def inner(*args, **kwargs):
threads = []
for i in range(num_threads):
thread = threading.Thread(target=func, args=args, kwargs=kwargs)
threads.append(thread)
for thread in threads:
thread.start()
for thread in threads:
thread.join()
return inner
return wrapper
if __name__ == '__main__':
color_check('pil')
mono_check('pil')
+1 -1
View File
@@ -197,7 +197,7 @@ def test_swirl():
image = img_as_float(data.checkerboard())
swirl_params = {'radius': 80, 'rotation': 0, 'order': 2, 'mode': 'reflect'}
with expected_warnings(['Bi-quadratic.*bug']):
swirled = tf.swirl(image, strength=10, **swirl_params)
unswirled = tf.swirl(swirled, strength=-10, **swirl_params)