Got `AttributeError` when start `pytest` session
DKorytkin opened this issue ยท 4 comments
Describe the bug
Got INTERNALERROR> AttributeError: 'ModuleWrapper' object has no attribute 'cpu_freq'
when start pytest
I guess psutil
has diffrent methods for different versions ๐
And need just to pin a minimal version which plugin supports
psutil.cpu_freq()
was added in 5.1.0
To Reproduce
- Install the latest version of
pytest-monitor
pip3 install git+https://github.com/CFMTech/pytest-monitor.git
- Run
python3 -m pytest -lvv tests/backend/unit/
Expected behavior
run tests with pytest-monitor
plugin
Exeption
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR> File "python3.7/site-packages/_pytest/main.py", line 105, in wrap_session
INTERNALERROR> config.hook.pytest_sessionstart(session=session)
INTERNALERROR> File "/python3.7/site-packages/pluggy/__init__.py", line 617, in __call__
INTERNALERROR> return self._hookexec(self, self._nonwrappers + self._wrappers, kwargs)
INTERNALERROR> File "/python3.7/site-packages/pluggy/__init__.py", line 222, in _hookexec
INTERNALERROR> return self._inner_hookexec(hook, methods, kwargs)
INTERNALERROR> File "/python3.7/site-packages/pluggy/__init__.py", line 216, in <lambda>
INTERNALERROR> firstresult=hook.spec_opts.get('firstresult'),
INTERNALERROR> File "/python3.7/site-packages/pluggy/callers.py", line 201, in _multicall
INTERNALERROR> return outcome.get_result()
INTERNALERROR> File "/python3.7/site-packages/pluggy/callers.py", line 76, in get_result
INTERNALERROR> raise ex[1].with_traceback(ex[2])
INTERNALERROR> File "/python3.7/site-packages/pluggy/callers.py", line 175, in _multicall
INTERNALERROR> next(gen) # first yield
INTERNALERROR> File "/python3.7/site-packages/pytest_monitor/pytest_monitor.py", line 174, in pytest_sessionstart
INTERNALERROR> session.config.option.mtr_tags)
INTERNALERROR> File "/python3.7/site-packages/pytest_monitor/session.py", line 80, in compute_info
INTERNALERROR> self.set_environment_info(ExecutionContext())
INTERNALERROR> File "/python3.7/site-packages/pytest_monitor/sys_utils.py", line 39, in __init__
INTERNALERROR> self.__cpu_freq_base = psutil.cpu_freq().current
INTERNALERROR> AttributeError: 'ModuleWrapper' object has no attribute 'cpu_freq'
Desktop (please complete the following information):
- OS: macOs
- Version 10.15.5 (19F101)
Additional context
psutil 2.1.1
Hello
Thanks for this detailed description. Indeed psutil has different methods depending on the version you are using.
I should have put a minimal version to this dependency... I'll prepare a patch for that.
Thanks again for the report. :)
Hello @DKorytkin
I will constraint the requirement on psutil to be in version at least 5.1+
I am not willing to handle too old versions.
@js-dieu, thanks. I also suggest to pin it in setup.py
Just in case when psutil
already installed, but old version.
It helps to understand that need to update psutil
when tried to install pytest-monitor
@DKorytkin you are right. I did it on a rush and completely forgot the setup.py file.
Note that conda packages already handle these requirements, but as you noticed pip don't.