From a5c76209c63ba5ed0c0da7b718441fd6e40f8e31 Mon Sep 17 00:00:00 2001 From: sandcha Date: Tue, 26 Nov 2024 14:49:12 +0100 Subject: [PATCH] Capture printed trace log in test And do not init simulation before TestItem.runtest that will instanciate it with trace options --- .../tools/test_runner/test_yaml_runner.py | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/core/tools/test_runner/test_yaml_runner.py b/tests/core/tools/test_runner/test_yaml_runner.py index 4b19a7aba..0793f3a51 100644 --- a/tests/core/tools/test_runner/test_yaml_runner.py +++ b/tests/core/tools/test_runner/test_yaml_runner.py @@ -82,7 +82,6 @@ def __init__(self, test, **kwargs) -> None: super().__init__(name="", path="", baseline_tax_benefit_system=TaxBenefitSystem(), test=test, options={}, **kwargs) self.tax_benefit_system: TaxBenefitSystem = self.baseline_tax_benefit_system - self.simulation = Simulation() class TestVariable(Variable): @@ -206,20 +205,27 @@ def test_performance_tables_option_output() -> None: clean_performance_files(paths) -def test_trace() -> None: +def test_trace(capsys) -> None: testFile = TestFile.from_parent(parent=None) test = { "input": {"salary": {"2017-01": 2000}}, "output": {"salary": {"2017-01": 2000}}, } test_item = TestItem.from_parent(parent=testFile, test=test) - test_item.options = {"verbose": True} - + + # TestItem init should instanciate the TaxBenefitSystem assert test_item.tax_benefit_system.get_variable("salary") is not None - + + test_item.options = {"verbose": True} test_item.runtest() - - assert test_item.simulation.trace + captured = capsys.readouterr() + + # TestItem.runtest should set the trace attribute from the 'verbose' option + assert test_item.simulation.trace is True + assert test_item + + # TestItem.runtest should run print_computation_log + assert captured.out is not '' def clean_performance_files(paths: list[str]) -> None: