pytest-dev / pytest-timeout

MIT License
216 stars 64 forks source link

is_debugging() fails when run with pytest-cov #66

Closed pshv closed 4 years ago

pshv commented 4 years ago

There's an error with is_debugging() method introduced in 1.4.0 and pytest-cov plugin. I'm running on Windows and using following test-case to reproduce:

  1. Install pytest, pytest-timeout, pytest-cov
  2. Run following file
    
    import time

def test(): time.sleep(3)

with following params in PyCharm
`--timeout=3 --cov=test.py`

The error I got is 

test.py::test PASSED [100%]Exception in thread pytest_timeout test.py::test: Traceback (most recent call last): File "C:\Python37\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Python37\lib\threading.py", line 1178, in run self.function(*self.args, **self.kwargs) File "C:\Python37\lib\site-packages\pytest_timeout.py", line 378, in timeout_timer if is_debugging(): File "C:\Python37\lib\site-packages\pytest_timeout.py", line 177, in is_debugging if name in trace_func.module: AttributeError: 'coverage.CTracer' object has no attribute 'module'


More than that, when I run the same from command line (meaning not in debug mode) and with time.sleep(300) instead, timeout doesn't work for me at all, and at the same time all the same steps without --cov=test.py, works just fine
flub commented 4 years ago

Thanks for the report! And apologies for breaking coverage support. I just released 1.4.1 which I think should fix this.

/cc @Mattwmaster58

Mattwmaster58 commented 4 years ago

Oof, seems like I assumed every function object would have a __module__ attribute which clearly wasn't the case. Good call to use inspect.getmodule, and a test as well!