Exemple #1
0
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'
Exemple #2
0
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'
Exemple #3
0
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'
Exemple #4
0
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'
Exemple #5
0
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
Exemple #6
0
def test_single_section(capsys):
    with timeit_section('single_section'):
        pass

    captured = capsys.readouterr()
    assert captured.out == '->>>>>>>>         500.0ms      single_section\n'
Exemple #7
0
 def function_outer():
     with timeit_section('function_outer:section'):
         pass
     function_middle()
Exemple #8
0
 def function_inner():
     with timeit_section('function_inner:section_1'):
         pass
     with timeit_section('function_inner:section_2'):
         raise Exception('')