From c94ac05841b9bee6828e347bbc2a1fa61168c745 Mon Sep 17 00:00:00 2001 From: Neil Wu Date: Tue, 15 Aug 2023 16:11:57 -0700 Subject: [PATCH] make nsga2 tests optional --- tests/test_nsga2_multi_objective.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/test_nsga2_multi_objective.py b/tests/test_nsga2_multi_objective.py index 0fe7f57a..e4f716f9 100644 --- a/tests/test_nsga2_multi_objective.py +++ b/tests/test_nsga2_multi_objective.py @@ -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"] @@ -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: @@ -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: @@ -71,3 +77,6 @@ def test_opt(self, n_obj): if __name__ == "__main__": unittest.main() + unittest.main() + unittest.main() + unittest.main()