def test_print_solution_returns_value(): """Ensure that `_print_solution` returns `True` if there was a solution.""" solver_with_solutions = mock.Mock() solver_with_solutions.solve.return_value = [["foo"]] assert _print_solution(solver_with_solutions) solver_without_solutions = mock.Mock() solver_without_solutions.solve.return_value = [] assert not _print_solution(solver_without_solutions)
def test_print_solution(capsys): """Ensure that we print the solution, without printing duplicates.""" solver = mock.Mock() solver.solve.return_value = [["foo", "bar"], ["bar", "foo"]] _print_solution(solver) out, _ = capsys.readouterr() # Should print the first item, but then skip the second item as it's been # seen. assert out == "foo bar\n"