Unverified Commit 18d4369c authored by Peter Oehme's avatar Peter Oehme Committed by René Fritze
Browse files

add decorator for required modules

parent 1327fd91
......@@ -7,11 +7,13 @@ import os
import sys
from pprint import pformat
from functools import wraps
import importlib
import hypothesis
import numpy as np
from pickle import dump, load
from pkg_resources import resource_filename, resource_stream
from pytest import skip
from pymor.algorithms.basic import almost_equal, relative_error
......@@ -92,3 +94,20 @@ def might_exceed_deadline(deadline=-1):
return hypothesis.settings(deadline=dl)(func)(*args, **kwargs)
return _inner_wrapper
return _outer_wrapper
def skip_if_missing(module_name):
"""Wrapper for requiring certain modules on tests."""
def _outer_wrapper(func):
@wraps(func)
def _inner_wrapper(*args, **kwargs):
try:
module = importlib.import_module(module_name)
except ImportError as ie:
if not os.environ.get('DOCKER_PYMOR', False):
skip_string = 'skipped test due to missing module ' + module_name
skip(skip_string)
raise ie
func(*args, **kwargs)
return _inner_wrapper
return _outer_wrapper
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment