<div dir="ltr">Hi Bruno,<div><br></div><div>Thanks for the quick reply!</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">pytest 3.0 (which should be released soon) introduces two new hooks:</span><br></blockquote><div><br></div><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 "soon"?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">In current pytest I think one would have to resort to printing elapsed time in the fixture functions manually.</span></blockquote><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Unfortunately, printing is subject to log capture plug-ins, so it's very inconvenient. I see your example plug-in uses printing as well. 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'm not sure how to pass info from your example `pytest_fixture_setup()` to the reporting function. Any hints?</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Thanks again,</span></div><div><br></div><div>André</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jul 23, 2016 at 10:04 AM, Bruno Oliveira <span dir="ltr"><<a href="mailto:nicoddemus@gmail.com" target="_blank">nicoddemus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Fri, Jul 22, 2016 at 1:23 PM André Caron <<a href="mailto:andre.l.caron@gmail.com" target="_blank">andre.l.caron@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Greetings from Canada :-)</div></blockquote><div><br></div><div><span style="line-height:1.5">Hi André, greetings from Brazil. :)</span></div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I'm trying to speed up the CI cycle on one project I'm working on and I'm trying to to figure out where time is spent by the test suite.</div><div><br></div><div>I just discovered the excellent --durations option[1] which prints a neat report containing the slowest tests.</div><div><br></div><div>This has been of much help to get started (I've already spotted a few tests to optimize), but it doesn't seem to track time spent in test fixtures. I'd like to track metrics for test fixtures, including number of calls, total time spent in order to optimize the slower fixtures.</div></div></blockquote><div><br></div></span><div>pytest 3.0 (which should be released soon) introduces two new hooks:</div><div><br></div><div>* pytest_fixture_setup(fixturedef, request): executes fixture setup;</div><div>* pytest_fixture_post_finalizer(fixturedef): called after the fixture's finalizer.</div><div><br></div><div>A plugin could use this to measure fixture setup time:</div><div><br></div><div>@pytest.hookimpl(hookwrapper=True)</div><div>def pytest_fixture_setup(fixturedef, request):</div><div> started = time.time()</div><div> yield </div><div> elapsed = time.time() - started</div><div> print('fixture', <a href="http://fixturedef.name" target="_blank">fixturedef.name</a>, 'setup took %.3fs' % elapsed)</div><div><br></div><div>In current pytest I think one would have to resort to printing elapsed time in the fixture functions manually.</div><div><br></div><div>Hope this helps,</div><div>Bruno.</div></div></div>
</blockquote></div><br></div>