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 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')()
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
......
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