def test_combines_profs(): plugin = Profiling(False) plugin.profs = [sentinel.prof0, sentinel.prof1] with patch('pstats.Stats') as Stats: plugin.pytest_sessionfinish(Mock(), Mock()) Stats.assert_called_once_with(sentinel.prof0) Stats.return_value.add.assert_called_once_with(sentinel.prof1) assert Stats.return_value.dump_stats.called
def test_writes_summary_svg(): plugin = Profiling(True) plugin.profs = [sentinel.prof] terminalreporter = Mock() with patch('pstats.Stats'): with patch('pipes.Template'): plugin.pytest_sessionfinish(Mock(), Mock()) plugin.pytest_terminal_summary(terminalreporter) assert 'SVG' in terminalreporter.write.call_args[0][0]
def test_writes_summary(): plugin = Profiling(False) plugin.profs = [sentinel.prof] terminalreporter, stats = Mock(), Mock() with patch('pstats.Stats', return_value=stats) as Stats: plugin.pytest_sessionfinish(Mock(), Mock()) plugin.pytest_terminal_summary(terminalreporter) assert 'Profiling' in terminalreporter.write.call_args[0][0] assert Stats.called_with(stats, stream=terminalreporter)
def test_generates_svg(): plugin = Profiling(True) plugin.profs = [sentinel.prof] with patch('pstats.Stats'): with patch('pipes.Template') as Template: plugin.pytest_sessionfinish(Mock(), Mock()) assert any('gprof2dot' in args[0][0] for args in Template.return_value.append.call_args_list) assert Template.return_value.copy.called
def test_hooks_pyfunc_call(): assert getattr(Profiling.pytest_pyfunc_call, 'tryfirst') multicall, pyfuncitem, plugin = Mock(), Mock(), Profiling(False) pyfuncitem.name.__add__ = Mock() with patch('os.path.join', return_value=sentinel.join): with patch('pytest_profiling.cProfile') as cProfile: plugin.pytest_pyfunc_call(multicall, pyfuncitem) assert cProfile.runctx.called args, kwargs = cProfile.runctx.call_args assert kwargs['filename'] == sentinel.join assert not multicall.execute.called eval(*args) assert multicall.execute.called assert plugin.profs == [sentinel.join]
def test_creates_prof_dir(): with patch('os.makedirs', side_effect=OSError) as makedirs: Profiling(False).pytest_sessionstart(Mock()) makedirs.assert_called_with('prof')