[pytest-dev] How to add delay before processing captured output

Nikolaus Rath Nikolaus at rath.org
Thu Feb 18 12:18:56 EST 2016


On Feb 18 2016, Bruno Oliveira <nicoddemus-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
> Hi Nokolaus,
>
> On Wed, Feb 17, 2016 at 7:07 PM Nikolaus Rath <Nikolaus-BTH8mxji4b0 at public.gmane.org> wrote:
>
>> Is there a way to add a delay that is (1) only incurred when a test
>> fails and (2) executed right after the test fails (ie., before the capfd
>> finalizer runs)?
>>
>
> One way to execute something right after the test function is to implement
> the pytest_pyfunc_call, which is used to call python test functions:
>
> @pytest.mark.hookwrapper
> def pytest_pyfunc_call(pyfuncitem):
>     outcome = yield
>     failed = outcome.excinfo is not None
>     if failed:
>         wait_a_moment()
>
> You might even use marks to add this "wait time" only to marked functions,
> instead of all tests.
>
> I don't have time to look up and see if this will work with interaction
> with the capture plugin, but it's worth a shot.

Works perfectly, thanks!


Best,
-Nikolaus

-- 
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«


More information about the pytest-dev mailing list