def test_nested_sections(capsys): with timeit_section('section_outer'): with timeit_section('section_inner'): pass captured = capsys.readouterr() assert captured.out == '->>>>>>>> 500.0ms | section_inner\n' \ '->>>>>>>> 2200.0ms section_outer\n'
def test_nested_section_rising_exception(capsys): with pytest.raises(Exception): with timeit_section('section_outer'): with timeit_section('section_inner'): raise Exception('') captured = capsys.readouterr() assert captured.out == '->>>>>>>> 600.0ms | section_inner\n' \ '->>>>>>>> 2800.0ms section_outer\n'
def test_double_section(capsys): with timeit_section('section_1'): pass with timeit_section('section_2'): pass captured = capsys.readouterr() assert captured.out == '->>>>>>>> 500.0ms section_1\n' \ '->>>>>>>> 1000.0ms section_2\n'
def test_section_rising_exception(capsys): with pytest.raises(Exception): with timeit_section('section_1'): raise Exception('') with timeit_section('section_2'): pass captured = capsys.readouterr() assert captured.out == '->>>>>>>> 500.0ms section_1\n' \ '->>>>>>>> 1000.0ms section_2\n'
def test_section_extra_data(capsys): with timeit_section('section', extra_data_to_print="Extra, extra! Read all about it!"): pass expected = '->>>>>>>> 500.0ms section - Extra, extra! Read all about it!\n' captured = capsys.readouterr() assert captured.out == expected
def test_single_section(capsys): with timeit_section('single_section'): pass captured = capsys.readouterr() assert captured.out == '->>>>>>>> 500.0ms single_section\n'
def function_outer(): with timeit_section('function_outer:section'): pass function_middle()
def function_inner(): with timeit_section('function_inner:section_1'): pass with timeit_section('function_inner:section_2'): raise Exception('')