Skip to content

Commit a5c7620

Browse files
committed
Capture printed trace log in test
And do not init simulation before TestItem.runtest that will instanciate it with trace options
1 parent 6a52fb2 commit a5c7620

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

tests/core/tools/test_runner/test_yaml_runner.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ def __init__(self, test, **kwargs) -> None:
8282
super().__init__(name="", path="", baseline_tax_benefit_system=TaxBenefitSystem(), test=test, options={}, **kwargs)
8383

8484
self.tax_benefit_system: TaxBenefitSystem = self.baseline_tax_benefit_system
85-
self.simulation = Simulation()
8685

8786

8887
class TestVariable(Variable):
@@ -206,20 +205,27 @@ def test_performance_tables_option_output() -> None:
206205
clean_performance_files(paths)
207206

208207

209-
def test_trace() -> None:
208+
def test_trace(capsys) -> None:
210209
testFile = TestFile.from_parent(parent=None)
211210
test = {
212211
"input": {"salary": {"2017-01": 2000}},
213212
"output": {"salary": {"2017-01": 2000}},
214213
}
215214
test_item = TestItem.from_parent(parent=testFile, test=test)
216-
test_item.options = {"verbose": True}
217-
215+
216+
# TestItem init should instanciate the TaxBenefitSystem
218217
assert test_item.tax_benefit_system.get_variable("salary") is not None
219-
218+
219+
test_item.options = {"verbose": True}
220220
test_item.runtest()
221-
222-
assert test_item.simulation.trace
221+
captured = capsys.readouterr()
222+
223+
# TestItem.runtest should set the trace attribute from the 'verbose' option
224+
assert test_item.simulation.trace is True
225+
assert test_item
226+
227+
# TestItem.runtest should run print_computation_log
228+
assert captured.out is not ''
223229

224230

225231
def clean_performance_files(paths: list[str]) -> None:

0 commit comments

Comments
 (0)