diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 4cc51ecd..99593be6 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -68,7 +68,7 @@ jobs: - name: Test run: | - python -m unittest discover -s tests + pytest tests -m "not slow" --durations=0 - name: Install pypa/build run: | diff --git a/pyproject.toml b/pyproject.toml index 6013bdf7..0083582b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,6 @@ docs = [ "sphinx_copybutton>=0.5.1", "sphinx-sitemap>=2.5.0", ] - ax = [ "ax-platform >=0.3.5" ] @@ -78,3 +77,9 @@ line-length = 88 testpaths = [ "tests", ] +pythonpath = [ + "tests", +] +markers = [ + "slow: marks tests as slow (deselect with '-m \"not slow\"')", +] diff --git a/tests/optimization_problem_fixtures.py b/tests/optimization_problem_fixtures.py index e8f05683..486f55ea 100644 --- a/tests/optimization_problem_fixtures.py +++ b/tests/optimization_problem_fixtures.py @@ -76,6 +76,9 @@ def allow_test_failure_percentage( class TestProblem(OptimizationProblem): + # To prevent Pytest interpreting this class as test: + __test__ = False + @property def optimal_solution(self): """Must return X, F, and if it has, G.""" diff --git a/tests/test_binding.py b/tests/test_binding.py index ae0f9a4f..84b6b471 100644 --- a/tests/test_binding.py +++ b/tests/test_binding.py @@ -11,9 +11,6 @@ class Test_Binding(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): component_system = ComponentSystem(2) diff --git a/tests/test_buffer_capacity.py b/tests/test_buffer_capacity.py index 3dced6e6..31920447 100644 --- a/tests/test_buffer_capacity.py +++ b/tests/test_buffer_capacity.py @@ -11,9 +11,6 @@ class TestBufferCapacity(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.components_simple = ComponentSystem(2, charges=[1, 2]) diff --git a/tests/test_cache.py b/tests/test_cache.py index d44da455..16f8fb49 100644 --- a/tests/test_cache.py +++ b/tests/test_cache.py @@ -4,8 +4,6 @@ class TestCache(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): self.cache_dict = ResultsCache(use_diskcache=False) diff --git a/tests/test_cadet_adapter.py b/tests/test_cadet_adapter.py index 78df4c9e..7aba6688 100644 --- a/tests/test_cadet_adapter.py +++ b/tests/test_cadet_adapter.py @@ -35,9 +35,6 @@ def detect_cadet(install_path: Optional[Path] = None): class Test_Adapter(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - @unittest.skipIf(found_cadet is False, "Skip if CADET is not installed.") def test_check_cadet(self): simulator = Cadet(install_path) @@ -155,6 +152,7 @@ def simulation_results(request: pytest.FixtureRequest): return simulation_results @pytest.mark.parametrize("process", test_cases, indirect=True) +@pytest.mark.slow class TestProcessWithLWE: def return_process_config(self, process: Process) -> dict: @@ -566,6 +564,7 @@ def test_sensitivity_config(self, process: Process): @pytest.mark.parametrize("simulation_results", test_cases, indirect=True) +@pytest.mark.slow class TestResultsWithLWE: def test_trigger_simulation(self, simulation_results): """ diff --git a/tests/test_carousel.py b/tests/test_carousel.py index 6e643ad9..824507db 100644 --- a/tests/test_carousel.py +++ b/tests/test_carousel.py @@ -12,9 +12,6 @@ class Test_Carousel(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(2) diff --git a/tests/test_compartment.py b/tests/test_compartment.py index 62a4074e..ba68bea8 100644 --- a/tests/test_compartment.py +++ b/tests/test_compartment.py @@ -9,9 +9,6 @@ class Test_CompartmentBuilder(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(2) diff --git a/tests/test_difference.py b/tests/test_difference.py index 6a61b6d6..9a2cb2c7 100644 --- a/tests/test_difference.py +++ b/tests/test_difference.py @@ -40,8 +40,6 @@ from CADETProcess.comparison import SSE class TestSSE(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def test_metric(self): # Compare with itself @@ -76,8 +74,6 @@ def test_metric(self): from CADETProcess.comparison import NRMSE class TestNRMSE(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def test_metric(self): # Compare with itself @@ -112,8 +108,6 @@ def test_metric(self): from CADETProcess.comparison import PeakHeight class TestPeakHeight(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): # 2 Components, gaussian peaks, constant flow @@ -202,8 +196,6 @@ def test_metric(self): from CADETProcess.comparison import PeakPosition class TestPeakPosition(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): # 2 Components, gaussian peaks, constant flow @@ -275,8 +267,6 @@ def test_metric(self): from CADETProcess.comparison import Shape class TestShape(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): # 2 Components, gaussian peaks, constant flow @@ -396,8 +386,6 @@ def test_metric(self): class TestFractionation(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): fraction_1 = Fraction( diff --git a/tests/test_equilibrium.py b/tests/test_equilibrium.py index c1a9b6e8..20ec842f 100644 --- a/tests/test_equilibrium.py +++ b/tests/test_equilibrium.py @@ -10,8 +10,6 @@ class TestReactionEquilibrium(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): component_system = ComponentSystem(2) @@ -171,8 +169,6 @@ def test_reaction_equilibrium(self): class TestAdsorptionEquilibrium(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): component_system_mono = ComponentSystem() diff --git a/tests/test_events.py b/tests/test_events.py index 96c1fdcf..ded6eb98 100644 --- a/tests/test_events.py +++ b/tests/test_events.py @@ -11,7 +11,7 @@ Notes ----- Since the EventHandler defines an interface, that requires the -implementation of some methods, a TestHandler class is defined. +implementation of some methods, a HandlerFixture class is defined. Maybe this is too complicated, just use Process instead? """ @@ -31,7 +31,8 @@ plot = True -class TestPerformer(Structure): +class PerformerFixture(Structure): + n_entries = 4 n_coeff = 4 @@ -79,10 +80,11 @@ def section_dependent_parameters(self): return parameters -class TestHandler(CADETProcess.dynamicEvents.EventHandler): +class HandlerFixture(CADETProcess.dynamicEvents.EventHandler): + def __init__(self): self.name = None - self.performer = TestPerformer() + self.performer = PerformerFixture() super().__init__() @property @@ -100,7 +102,7 @@ def parameters(self, parameters): except KeyError: pass - super(TestHandler, self.__class__).parameters.fset(self, parameters) + super(HandlerFixture, self.__class__).parameters.fset(self, parameters) @property def section_dependent_parameters(self): @@ -117,11 +119,8 @@ def polynomial_parameters(self): class Test_Events(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setup_event_handler(self, add_events=False): - event_handler = TestHandler() + event_handler = HandlerFixture() event_handler.cycle_time = 20 if add_events: diff --git a/tests/test_flow_sheet.py b/tests/test_flow_sheet.py index 1e19563f..01e8d86e 100644 --- a/tests/test_flow_sheet.py +++ b/tests/test_flow_sheet.py @@ -161,9 +161,6 @@ def setup_ssr_flow_sheet(component_system=None): class TestFlowSheet(unittest.TestCase): """Test general functionatlity of `FlowSheet` class.""" - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(2) @@ -995,9 +992,6 @@ class TestCstrFlowRate(unittest.TestCase): is set, it has properties similar to an `Inlet`. """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(2) @@ -1100,8 +1094,6 @@ def test_state_update(self): np.testing.assert_almost_equal(cstr_out, cstr_out_expected) class TestPorts(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): self.setup_mct_flow_sheet() @@ -1561,9 +1553,6 @@ def test_set_output_state(self): class TestFlowRateMatrix(unittest.TestCase): """Test calculation of flow rates with another simple testcase by @daklauss""" - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(1) @@ -1698,8 +1687,6 @@ def test_matrix_example(self): class TestFlowRateSelfMatrix(unittest.TestCase): """Test special case where one unit is connected to itself.""" - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): self.component_system = ComponentSystem(1) @@ -1794,9 +1781,6 @@ class TestSingularFlowMatrix(unittest.TestCase): """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(1) diff --git a/tests/test_fractions.py b/tests/test_fractions.py index 46a9c15e..4ed9b21b 100644 --- a/tests/test_fractions.py +++ b/tests/test_fractions.py @@ -6,9 +6,6 @@ class Test_Fractions(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def create_fractions(self): m_0 = np.array([0, 0]) frac0 = CADETProcess.fractionation.Fraction(m_0, 1) diff --git a/tests/test_individual.py b/tests/test_individual.py index c7696c0b..887f6808 100644 --- a/tests/test_individual.py +++ b/tests/test_individual.py @@ -32,9 +32,6 @@ def test_hash_array(self): class TestIndividual(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): x = [1, 2] f = [-1] diff --git a/tests/test_optimization_problem.py b/tests/test_optimization_problem.py index 452d45d5..c49e6966 100644 --- a/tests/test_optimization_problem.py +++ b/tests/test_optimization_problem.py @@ -112,10 +112,6 @@ def min_results_2(cheap_results): class Test_OptimizationVariable(unittest.TestCase): - - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.evaluation_object = EvaluationObject() @@ -330,14 +326,10 @@ def test_transform(self): ) -from tests.test_events import TestHandler +from tests.test_events import HandlerFixture class Test_OptimizationVariableEvents(unittest.TestCase): - - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): - evaluation_object = TestHandler() + evaluation_object = HandlerFixture() evt = evaluation_object.add_event( 'single_index_1D', 'performer.array_1d', 1, indices=0, time=1 @@ -571,7 +563,7 @@ def test_polynomial(self): def test_multi_eval_obj(self): """Test setting indexed variables for multiple evaluation objects.""" - evaluation_object_2 = TestHandler() + evaluation_object_2 = HandlerFixture() evt = evaluation_object_2.add_event( 'multi_index_ND', 'performer.ndarray', @@ -669,9 +661,6 @@ def setup_optimization_problem( class Test_OptimizationProblemSimple(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): optimization_problem = OptimizationProblem('simple', use_diskcache=False) @@ -708,9 +697,6 @@ def test_bounds(self): class Test_OptimizationProblemLinCon(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): optimization_problem = setup_optimization_problem( n_lincon=1, use_diskcache=False @@ -832,9 +818,6 @@ def test_initial_values(self): class Test_OptimizationProblemDepVar(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): optimization_problem = OptimizationProblem('simple', use_diskcache=False) @@ -1007,9 +990,6 @@ def test_initial_values(self): class Test_OptimizationProblemJacobian(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): def single_obj_single_var(x): return x[0]**2 @@ -1095,9 +1075,6 @@ class Test_OptimizationProblemConstraintTransforms(unittest.TestCase): tests if `A_transformed` and `b_transformed` properties are correctly computed. """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setup(self): settings.working_directory = './test_problem' @@ -1229,9 +1206,6 @@ class Test_OptimizationProblemEvaluator(unittest.TestCase): """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): eval_obj = EvaluationObject() @@ -1309,9 +1283,6 @@ def test_cache(self): class Test_MultiEvaluationObjects(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): eval_obj_1 = EvaluationObject(name='foo') eval_obj_2 = EvaluationObject(name='bar') diff --git a/tests/test_optimization_results.py b/tests/test_optimization_results.py index 48ba9418..8f616e12 100644 --- a/tests/test_optimization_results.py +++ b/tests/test_optimization_results.py @@ -32,9 +32,6 @@ def setup_optimization_results( class TestOptimizationResults(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.optimization_results = setup_optimization_results() diff --git a/tests/test_optimizer_behavior.py b/tests/test_optimizer_behavior.py index acd54301..b0af2265 100644 --- a/tests/test_optimizer_behavior.py +++ b/tests/test_optimizer_behavior.py @@ -178,7 +178,7 @@ def optimizer(request): # %% Tests - +@pytest.mark.slow def test_convergence(optimization_problem: TestProblem, optimizer: OptimizerBase): # only test problems that the optimizer can handle. The rest of the tests # will be marked as passed @@ -194,7 +194,7 @@ def test_convergence(optimization_problem: TestProblem, optimizer: OptimizerBase else: optimization_problem.test_if_solved(results, MOO_TEST_KWARGS) - +@pytest.mark.slow def test_from_initial_values( optimization_problem: TestProblem, optimizer: OptimizerBase ): @@ -233,7 +233,7 @@ def __call__(self, results): raise RuntimeError("Max number of evaluations reached. Aborting!") self.n_calls += 1 - +@pytest.mark.slow def test_resume_from_checkpoint( optimization_problem: TestProblem, optimizer: OptimizerBase ): diff --git a/tests/test_parallelization_adapter.py b/tests/test_parallelization_adapter.py index 788057b1..ea594dbd 100644 --- a/tests/test_parallelization_adapter.py +++ b/tests/test_parallelization_adapter.py @@ -42,9 +42,6 @@ class TestParallelizationBackend(unittest.TestCase): """Test initializing parallelization backends and n_cores attribute.""" - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def test_n_cores(self): with self.assertRaises(ValueError): sequential_backend = SequentialBackend(n_cores=n_cores) @@ -89,9 +86,6 @@ class TestParallelEvaluation(unittest.TestCase): """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def tearDown(self): shutil.rmtree('./tmp', ignore_errors=True) shutil.rmtree('./test_parallelization', ignore_errors=True) @@ -140,9 +134,6 @@ class TestOptimizerParallelizationBackend(unittest.TestCase): """ - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def tearDown(self): settings.working_directory = None diff --git a/tests/test_parameters.py b/tests/test_parameters.py index ab1f6500..3ad8bab8 100755 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -18,9 +18,6 @@ class TestDescription(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): param_with_description = Integer(description='foo') @@ -36,8 +33,6 @@ def test_modified_descriptor(self): class TestParameterDictionaries(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): class Model(Structure): @@ -91,9 +86,6 @@ def test_parameters_dict_setter(self): class TestConstant(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): const_int = Constant(value=0) @@ -120,9 +112,6 @@ class NoValue(Structure): class TestSwitch(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): switch = Switch(valid=['foo', 'bar'], default='foo') @@ -146,9 +135,6 @@ class InvalidDefault(Structure): class TestTyped(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): string_param = String(default='foo') @@ -197,9 +183,6 @@ class WrongDefaultType(Structure): class TestCallable(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): def default_method(x): return x @@ -229,9 +212,6 @@ def test_default(self): class TestRanged(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): bound_float_param = RangedFloat(lb=-1, ub=1, default=0) @@ -264,9 +244,6 @@ class InvalidDefault(Structure): class TestSizedUnified(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): sized_list = SizedList(size=4, default=0) @@ -344,9 +321,6 @@ class InvalidDefaultRange(Structure): class TestSizedDependent(unittest.TestCase): """Previous test methods for dependently sized parameters.""" - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): dep_1 = UnsignedInteger() @@ -448,9 +422,6 @@ class InvalidDefault(Structure): class TestPolynomial(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): poly_param = Polynomial(n_coeff=2, default=0) @@ -580,9 +551,6 @@ def test_default(self): class TestModulated(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): class Model(Structure): n_mod = 4 diff --git a/tests/test_population.py b/tests/test_population.py index 45fa7e66..a15a570e 100644 --- a/tests/test_population.py +++ b/tests/test_population.py @@ -22,8 +22,6 @@ def setup_population(n_ind, n_vars, n_obj, n_nonlin=0, n_meta=0, rng=None): class TestPopulation(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): x = [1, 2] @@ -238,8 +236,6 @@ def test_from_dict(self): class TestPareto(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): front = ParetoFront(3) diff --git a/tests/test_process.py b/tests/test_process.py index c489f4dc..3169aa57 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -7,9 +7,6 @@ class Test_process(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def create_process(self): return copy.deepcopy(process) diff --git a/tests/test_pymoo.py b/tests/test_pymoo.py index 5c2f9fbd..cc3428c1 100644 --- a/tests/test_pymoo.py +++ b/tests/test_pymoo.py @@ -8,8 +8,6 @@ class Test_OptimizationProblemSimple(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def tearDown(self): shutil.rmtree('./results_simple', ignore_errors=True) diff --git a/tests/test_reaction.py b/tests/test_reaction.py index 4d2b4eac..c8d7d7da 100644 --- a/tests/test_reaction.py +++ b/tests/test_reaction.py @@ -13,9 +13,6 @@ class Test_Reaction(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def create_simple_bulk_reaction(self, is_kinetic=True, k_fwd_min=100): # 0: NH4+(aq) <=> NH3(aq) + H+(aq) component_system = ComponentSystem() diff --git a/tests/test_sections.py b/tests/test_sections.py index f2c08b8d..e95d9fad 100644 --- a/tests/test_sections.py +++ b/tests/test_sections.py @@ -7,8 +7,6 @@ class TestGenerateIndices(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def test_generate_indices(self): shape = (3, 3) @@ -41,8 +39,6 @@ def test_generate_indices(self): class TestSection(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): self.constant_section_single = Section(0, 1, 1) @@ -108,8 +104,6 @@ def test_section_integral(self): class TestTimeLine(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def create_timeline_constant_single(self): """Piecewise constant sections with single entry.""" @@ -277,8 +271,6 @@ def test_tl_from_profile(self): class TestMultiTimeLine(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def create_timeline_constant_multi(self): """Piecewise constant sections with multiple entries managed by MultiTimeline.""" diff --git a/tests/test_solution.py b/tests/test_solution.py index deea5f92..5e727b22 100644 --- a/tests/test_solution.py +++ b/tests/test_solution.py @@ -91,8 +91,6 @@ class TestSolution(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): # 2 Components, constant concentration, constant flow @@ -427,8 +425,6 @@ def test_fraction_mass(self): class TestSliceSolution(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def setUp(self): # 2 Components, gaussian peaks, constant flow @@ -541,9 +537,6 @@ def test_total_concentration(self): class TestPlot(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): # 2 Components, gaussian peaks, constant flow self.solution_species = SolutionIO( diff --git a/tests/test_transform.py b/tests/test_transform.py index fef00043..3e8f868f 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -6,8 +6,6 @@ class Test_Transform(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) def test_input_range(self): transform = NormLinearTransform(0, 100) diff --git a/tests/test_unit_operation.py b/tests/test_unit_operation.py index 936135b6..8d5e2d40 100644 --- a/tests/test_unit_operation.py +++ b/tests/test_unit_operation.py @@ -41,9 +41,6 @@ class Test_Unit_Operation(unittest.TestCase): - def __init__(self, methodName='runTest'): - super().__init__(methodName) - def setUp(self): self.component_system = ComponentSystem(2)