<div dir="ltr">@Bruno: thanks, that&#39;s really enlightening!  In hindsight, this is rather obvious.  Still getting the hang of this :-)<div><br></div><div>I&#39;ll see if I can play around with a development build to flesh out my plug-in so that I can roll it out on my projects as soon as the 3.0 release is out.<br><div><br></div><div>@René: pytest-profiling does that and it is quite an interesting suggestion, at least as a temporay workaround.  However, my experience with function-level profiling is that it gives too much detail for this use case: you have to track down the fixture functions yourself and mentally remove all the noise in the graph to get a clear picture of where time is spent.  This is useful for a one-off analysis to perform a kind of &quot;blitz&quot;, but I&#39;d like a simplified text report I can show on each build so that I routinely take a quick look at the data.</div><div><br></div><div><div>André</div></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 23, 2016 at 11:25 AM, René Dudfield <span dir="ltr">&lt;<a href="mailto:renesd@gmail.com" target="_blank">renesd@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What about running pytest under the python profiler?<br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Sat, Jul 23, 2016 at 4:42 PM, Bruno Oliveira <span dir="ltr">&lt;<a href="mailto:nicoddemus@gmail.com" target="_blank">nicoddemus@gmail.com</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr"><br><br><div class="gmail_quote"><span><div dir="ltr">On Sat, Jul 23, 2016 at 11:29 AM André Caron &lt;<a href="mailto:andre.l.caron@gmail.com" target="_blank">andre.l.caron@gmail.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br></div><div dir="ltr"><div>These two new hooks look like what was looking for, so guess that yes, this will help a lot :-)  Do you have a ballpark-figure of how soon is &quot;soon&quot;?</div></div></blockquote><div><br></div></span><div>We are aiming for a release right after EuroPython, probably on the week of August 1st.</div><span><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="font-size:12.8px">Unfortunately, printing is subject to log capture plug-ins, so it&#39;s very inconvenient.  I see your example plug-in uses printing as well. </span></div></div></blockquote><div> </div></span><div>Oh sorry, I meant to demonstrate only how to use the new hooks, certainly printing is not the way to go.</div><span><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><span style="font-size:12.8px"> How would I go about printing a report at the end like the `--durations` argument does?  I assume I also need to use the `pytest_terminal_summary()` hook, but I&#39;m not sure how to pass info from your example `pytest_fixture_setup()` to the reporting function.  Any hints?</span></div></div></blockquote><div><br></div></span><div>You are right, `pytest_terminal_summary` is the best way to approach this. As to how to pass the information, aside from using global variables you could implement a plugin class yourself and register it during `pytest_configure`:</div><div><br></div><div><div>class MeasureSetupsPlugin:</div><div><br></div><div>    def __init__(self):</div><div>        self.elapsed_times = {}</div><div><br></div><div>    @pytest.hookimpl(hookwrapper=True)</div><div>    def pytest_fixture_setup(self, fixturedef, request):</div><span><div>        started = time.time()</div><div>        yield </div><div>        elapsed = time.time() - started</div></span><div>        self.elapsed_times.setdefault(<a href="http://fixturedef.name" target="_blank">fixturedef.name</a>, []).append(elapsed)</div><div>        </div><div>    def pytest_terminal_summary(self, terminalreporter):</div><div>        terminalreporter.write_sep(&quot;=&quot;, &quot;Fixture setup times (max)&quot;)</div><div>        for name, times in sorted(self.elapsed_times.items()):</div><div>            tr.write_line(&quot;%s %.3f&quot; % (name, max(times))</div><div><br></div><div><span style="line-height:1.5">def pytest_configure(config):</span><br></div><div>    config.pluginmanager.register(MeasureSetupsPlugin(), &#39;measure_setups&#39;)</div></div><div><br></div><div>You could decide to display all matter of different statistics during pytest_terminal_summary, like number of setups, slowest setup, etc.</div><div><br></div><div>Hope this helps!</div><div><br></div><div>Cheers,</div><div>Bruno.</div></div></div>
<br></div></div>_______________________________________________<br>
testing-in-python mailing list<br>
<a href="mailto:testing-in-python@lists.idyll.org" target="_blank">testing-in-python@lists.idyll.org</a><br>
<a href="http://lists.idyll.org/listinfo/testing-in-python" rel="noreferrer" target="_blank">http://lists.idyll.org/listinfo/testing-in-python</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>