Hey Brian,

On Tue, Oct 6, 2020 at 1:55 PM Brian Okken <variedthoug...@gmail.com> wrote:

> Hi,
>
> How do plugins support multiple pytest versions when the hook api changes?
> Or should they?
>
> Example.
> pytest-json-report ytest_warning_captured, which was deprecated in pytest
> 6.
> Looks like there's a new hook, pytest_warning_recorded, with similar
> enough API.
> I haven't tested it to see if the behavior is close enough to work as a
> drop in replacement.
>
> But even if it is, switching to the new api makes the plugin only work on
> pytest 6.0 and above.
>
> Is it recommended that plugin authors try to force users to always use the
> latest pytest?
>
What if they want to support older versions also?
>
> Is there a recommended way to say this?
>
> if  pytest version < 6, use one hook
> else use new hook
>
>
I believe it really depends on the plugin and how many users you have.
Certainly only supporting the latest pytest version is easier,
but if you must support older versions, then checking the version to decide
which hooks to implement is doable.

An alternative is to check if the new hook exists, like how we used to do
in pytest-xdist:

https://github.com/pytest-dev/pytest-xdist/blob/7bf654775dcd2fef9c0ebafbea982b7d180b740e/src/xdist/remote.py#L142-L164

Where we implement one hook or the other, giving preference to the new hook
when available.

Cheers,
Bruno.



>
> Thanks,
> Brian
> _______________________________________________
> pytest-dev mailing list
> pytest-dev@python.org
> https://mail.python.org/mailman/listinfo/pytest-dev
>
_______________________________________________
pytest-dev mailing list
pytest-dev@python.org
https://mail.python.org/mailman/listinfo/pytest-dev

Reply via email to