#57 Usage of pytest.__version__ breaks testing with prereleases
Opened 2 years ago by thecompiler. Modified 2 years ago

In conftest.py, you do:

if [int(x) for x in pytest.__version__.split(".")] < [3, 9, 0]:

This however breaks on prereleases, where __version__ is e.g. 7.0.0rc1:

E ValueError: invalid literal for int() with base 10: '0rc1'

In this specific case, I wonder whether that check is still necessary, given that pytest 3.9 was released back in 2018.

See https://github.com/pytest-dev/pytest/discussions/9415 and https://src.fedoraproject.org/rpms/pytest/pull-request/25 for context.

Thanks for finding that and I agree it is a bug. Is there a better test?

Like mentioned, in this case I believe you should just drop the compatibility code, unless you really need to keep compatible with such old pytest versions. If you need to keep it, the easiest solution would probably be to use if [int(x) for x in pytest.__version__.split(".")[:2]] < [3, 9]:

In the general case, sometimes e.g. using hasattr() is simpler - but I'm not aware of a straightforward way to ask pytest whether a given fixture exists.

Login to comment on this ticket.