[TIP] resume an interrupted pytest test run
nicoddemus at gmail.com
Mon Jan 29 07:04:01 PST 2018
On Mon, Jan 29, 2018 at 12:55 PM Wouter Overmeire <lodagro at gmail.com> wrote:
>> - How to handle reporting? Is there a way to save report per test, so
>>> while running and not postpone report generation up to the end?
>> Saving the report object is a little tricky (for example pytest-xdist
>> does it manually). Why do you want to do this?
> In the end I want a report on each test. If a run is aborted out of pytest
> control, there is no report available on the already completed tests, since
> pytest generates a report when all tests are completed. I would like to
> save a report on a test once a test is completed.
Actually pytest triggers a `pytest_runtest_logreport` for each test phase
(setup, call, teardown). You can implement that hook so you remove passed
tests from a list of "lastpassed" from the cache, similarly to how
--last-failed works. This should cover your use case of the run being
interrupted out of pytest's control because whenever you execute
`cache.set` it will write the cache value to disk.
In summary my suggestion is:
1. During `pytest_collection_modifyitems()`, if your plugin is active, get
the `lastpassed` list from the cache and remove all tests whose node id is
2. During each `pytest_runtest_logreport()`, if the test passed, save its
node id to the `lastpassed` list.
You can take a look at `_pytest/cacheprovider.py` for inspiration as well.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the testing-in-python