Skip to content

Commit

Permalink
make nsga2 tests optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ewu63 committed Aug 15, 2023
1 parent 23a8f86 commit c94ac05
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/test_nsga2_multi_objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ class TestNSGA2(OptTest):
name = "quadratic"
optName = "NSGA2"

def setUp(self):
try:
# First party modules
from pyoptsparse.pyNSGA2 import nsga2 # noqa: F401
except ImportError:
raise unittest.SkipTest("Optimizer not available: NSGA2")

def objfunc(self, xdict):
x = xdict["x"]
y = xdict["y"]
Expand All @@ -43,6 +50,9 @@ def setup_optProb(self, n_obj):
if n_obj == 2:
self.optProb.addObj("obj2")

@unittest.skipIf(
sys.platform == "win32", "test_nsga2_multi_objective.py fails on windows with two objectives! Skipping for now."
)
@parameterized.expand([(1,), (2,)])
def test_opt(self, n_obj):
if n_obj == 2:
Expand All @@ -51,11 +61,7 @@ def test_opt(self, n_obj):

# 300 generations will find x=(0,0), 200 or less will find x=(1,1)
optOptions = {"maxGen": 200}
if sys.platform == "win32":
warnings.warn(
"test_nsga2_multi_objective.py fails on windows with two objectives! Skipping for now.", stacklevel=2
)
return

sol = self.optimize(optOptions=optOptions)
tol = 1e-2
if n_obj == 1:
Expand All @@ -71,3 +77,6 @@ def test_opt(self, n_obj):

if __name__ == "__main__":
unittest.main()
unittest.main()
unittest.main()
unittest.main()

0 comments on commit c94ac05

Please sign in to comment.