ionelmc / pytest-benchmark

py.test fixture for benchmarking code
BSD 2-Clause "Simplified" License
1.22k stars 115 forks source link

Compatibility issue with pytest 7.2: Package `py` is used but not listed as dependency #226

Closed abey79 closed 1 year ago

abey79 commented 1 year ago

The package py is used at least here but is not listed in the dependencies.

Until version 7.1.x, Pytest would require py, but this has been dropped with Pytest 7.2, leading to the following error:

INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/_pytest/main.py", line 266, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/_pytest/config/__init__.py", line 1037, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pluggy/_hooks.py", line 277, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self.get_hookimpls(), kwargs, False)
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pluggy/_manager.py", line 80, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
INTERNALERROR>     raise ex[1].with_traceback(ex[2])
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pytest_benchmark/plugin.py", line 440, in pytest_configure
INTERNALERROR>     bs = config._benchmarksession = BenchmarkSession(config)
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pytest_benchmark/session.py", line 38, in __init__
INTERNALERROR>     self.logger = Logger(level, config=config)
INTERNALERROR>   File "/Users/hhip/Library/Caches/pypoetry/virtualenvs/vpype-l5n3HO8W-py3.10/lib/python3.10/site-packages/pytest_benchmark/logger.py", line 20, in __init__
INTERNALERROR>     self.term = py.io.TerminalWriter(file=sys.stderr)
INTERNALERROR> AttributeError: module 'py' has no attribute 'io'

This is fixed by explicitly manually installing py or adding py to the project.

alexprengere commented 1 year ago

It would be great if a release could be made with that change :wink:

nicoddemus commented 1 year ago

Just FYI, instead of depending on py, if the only dependency is the TerminalWriter, is to import it from from _pytest._io import TerminalWriter. While it is a private module, might be cleaner than depend on the deprecated py library.

ionelmc commented 1 year ago

@nicoddemus what's the difference between those 2 TerminalWriters?

nicoddemus commented 1 year ago

None, we vendored py.io into pytest a long time ago, and nothing on them has changed since then. 👍

pytest-xdist just did the same thing (importing TerminalWriter from _pytest._io).

ionelmc commented 1 year ago

@nicoddemus alright I've changed to what you've suggested but it turns out there were other issues, not sure if I've fixed correctly, can you take a look at https://github.com/ionelmc/pytest-benchmark/commit/c2e860f628116473e3134aba21492c04650d00a0 ?

nicoddemus commented 1 year ago

At first glance it looks good!

Given there were more changes than just an import, you might consider releasing a hotfix which just adds the py dependency, and after that make a new release which drops py completely (with the changes from c2e860f).

pyrito commented 1 year ago

Hi, thanks for the quick fix on the issue! When will pytest-benchmark make the new release?

ionelmc commented 1 year ago

Just released 4.0.0.

pyrito commented 1 year ago

@ionelmc when will it be on conda-forge? Referring to this specifically: https://github.com/conda-forge/pytest-benchmark-feedstock

ionelmc commented 1 year ago

@pyrito I don't own that repository not do I know much about conda packaging so that question would be best answered by opening an issue in that repository. I doubt they have notifications for releases so it's best to just ping the maintainers.