Skip to content
Snippets Groups Projects
Commit 620ab0ac authored by Mads M. Pedersen's avatar Mads M. Pedersen
Browse files

changed test_try_me to pytest

parent afdad44b
No related branches found
No related tags found
1 merge request!94Handle disabled mpi
'''
Created on 17. maj 2018
@author: mmpe
'''
import unittest
import topfarm
import pkgutil
import importlib import importlib
import inspect import os
import ast import pkgutil
import warnings import warnings
from topfarm.cost_models.fuga import lib_reader
import mock import mock
import pytest import pytest
import os import topfarm
class TestTryMe(unittest.TestCase):
def get_try_me_modules():
def test_try_me(self): package = topfarm
if os.name == 'posix' and "DISPLAY" not in os.environ: modules = []
pytest.xfail("No display") for _, modname, _ in pkgutil.walk_packages(package.__path__, package.__name__ + '.'):
package = topfarm with warnings.catch_warnings():
for _, modname, _ in pkgutil.walk_packages(package.__path__, package.__name__ + '.'): warnings.simplefilter("ignore")
with warnings.catch_warnings(): m = importlib.import_module(modname)
warnings.simplefilter("ignore") if 'try_me' in dir(m):
m = importlib.import_module(modname) modules.append(m)
if 'try_me' in dir(m): return modules
print("Checking %s.try_me" % modname)
with mock.patch.object(m, "__name__", "__main__"):
getattr(m, 'try_me')()
if __name__ == "__main__": @pytest.mark.parametrize("module", get_try_me_modules())
#import sys;sys.argv = ['', 'Test.testName'] def test_try_me(module):
unittest.main() # 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')()
import time import time
import numpy as np import numpy as np
import warnings import warnings
from wetb.utils.timing import print_time
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter('ignore', FutureWarning) warnings.simplefilter('ignore', FutureWarning)
from openmdao.api import Problem, ScipyOptimizeDriver, IndepVarComp from openmdao.api import Problem, ScipyOptimizeDriver, IndepVarComp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment