[TIP] Identifying slowest py.test fixtures
andre.l.caron at gmail.com
Sat Jul 23 07:29:36 PDT 2016
Thanks for the quick reply!
pytest 3.0 (which should be released soon) introduces two new hooks:
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"?
In current pytest I think one would have to resort to printing elapsed time
> in the fixture functions manually.
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?
On Sat, Jul 23, 2016 at 10:04 AM, Bruno Oliveira <nicoddemus at gmail.com>
> On Fri, Jul 22, 2016 at 1:23 PM André Caron <andre.l.caron at gmail.com>
>> Greetings from Canada :-)
> Hi André, greetings from Brazil. :)
>> 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.
>> I just discovered the excellent --durations option which prints a neat
>> report containing the slowest tests.
>> 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.
> pytest 3.0 (which should be released soon) introduces two new hooks:
> * pytest_fixture_setup(fixturedef, request): executes fixture setup;
> * pytest_fixture_post_finalizer(fixturedef): called after the fixture's
> A plugin could use this to measure fixture setup time:
> def pytest_fixture_setup(fixturedef, request):
> started = time.time()
> elapsed = time.time() - started
> print('fixture', fixturedef.name, 'setup took %.3fs' % elapsed)
> In current pytest I think one would have to resort to printing elapsed
> time in the fixture functions manually.
> Hope this helps,
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python