diff --git a/tests/test_try_me.py b/tests/test_try_me.py index 47a059e4e4287528a2af0665e79c318bd29aa042..5ede5239e7780a13d8df84f9e2a8b0c10a5aa1db 100644 --- a/tests/test_try_me.py +++ b/tests/test_try_me.py @@ -1,38 +1,29 @@ -''' -Created on 17. maj 2018 - -@author: mmpe -''' -import unittest -import topfarm -import pkgutil import importlib -import inspect -import ast +import os +import pkgutil import warnings -from topfarm.cost_models.fuga import lib_reader import mock import pytest -import os - +import topfarm -class TestTryMe(unittest.TestCase): - - def test_try_me(self): - if os.name == 'posix' and "DISPLAY" not in os.environ: - pytest.xfail("No display") - package = topfarm - for _, modname, _ in pkgutil.walk_packages(package.__path__, package.__name__ + '.'): - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - m = importlib.import_module(modname) - if 'try_me' in dir(m): - print("Checking %s.try_me" % modname) - with mock.patch.object(m, "__name__", "__main__"): - getattr(m, 'try_me')() +def get_try_me_modules(): + package = topfarm + modules = [] + for _, modname, _ in pkgutil.walk_packages(package.__path__, package.__name__ + '.'): + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + m = importlib.import_module(modname) + if 'try_me' in dir(m): + modules.append(m) + return modules -if __name__ == "__main__": - #import sys;sys.argv = ['', 'Test.testName'] - unittest.main() +@pytest.mark.parametrize("module", get_try_me_modules()) +def test_try_me(module): + # check that all try_me module examples run without errors + if os.name == 'posix' and "DISPLAY" not in os.environ: + pytest.xfail("No display") + print("Checking %s.try_me" % module.__name__) + with mock.patch.object(module, "__name__", "__main__"): + getattr(module, 'try_me')() diff --git a/topfarm/_topfarm.py b/topfarm/_topfarm.py index ed17bb88b954de5818e18ffdcfbda6d46b4639ce..ae4ecc8a780bca227138952c2e5a1ed884224c08 100644 --- a/topfarm/_topfarm.py +++ b/topfarm/_topfarm.py @@ -1,7 +1,6 @@ import time import numpy as np import warnings -from wetb.utils.timing import print_time with warnings.catch_warnings(): warnings.simplefilter('ignore', FutureWarning) from openmdao.api import Problem, ScipyOptimizeDriver, IndepVarComp