pytest-dev / pytest-timeout

MIT License
213 stars 64 forks source link

Pytest-timeout 2.0.2 crashes with `AttributeError: module 'py' has no attribute 'io'` #177

Closed cowlinator closed 3 months ago

cowlinator commented 3 months ago

Pytest-timeout is sometimes crashing pytest tests with the following exception:

File "C:\j\venv\lib\site-packages\pytest_timeout.py", line 400, in timeout_timer
  write_title("Timeout", sep="+")
File "C:\j\venv\lib\site-packages\pytest_timeout.py", line 447, in write_title
  width = py.io.get_terminal_width()
AttributeError: module 'py' has no attribute 'io'

My environment is:

pytest-timeout==2.0.2
pytest==7.4.4
pytest-cov==3.0.0
pytest-mock==3.6.1
Python 3.10.6

pip freeze does not list any entry for py. I do not believe py is installed. However, site-packages does have a file called py.py, which I believe is what is getting mistakenly imported by pytest_timeout.py.

import py
print(py.__file__)

prints C:\\Users\\<me>\\Documents\\<myproj>\\venv\\lib\\site-packages\\py.py

However, after running pip install py==1.11.0,

import py
print(py.__file__)

prints C:\\Users\\<me>\\Documents\\<myproj>\\venv\\lib\\site-packages\\py\\__init__.py

If pytest-timeout has a dependency on py, then installing pytest-timeout should also install py. Please add it to your install_requires in your setup.cfg.

flub commented 3 months ago

2.1.0 changed how the terminal width is retrieved. py was previously guaranteed to be available by pytest itself. please check the versions and changelog before reporting issues on old versions.