pytest-cov icon indicating copy to clipboard operation
pytest-cov copied to clipboard

installing pytest-cov causes all usage of pytest to fail

Open djhenderson opened this issue 4 years ago • 3 comments

Summary

After installing pytest-cov, previously working pytest usage now fails. Uninstalling pytest-cov allows pytest to run properly.

Expected vs actual result

Running pytest without any coverage options should work the same with and without pytest-cov installed. This is the result after I uninstalled pytest-cov.

> py -m pytest -x --capture=sys debug_tools\symbol_test.py
================================================= test session starts =================================================
platform win32 -- Python 3.9.2, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: D:\Users\Doug\dosprogs\DebugFix
collected 0 items

================================================ no tests ran in 0.05s ================================================

Reproducer

I have python 3.9.2 installed for all users.

In an admin terminal window I did py -m pip install -U pytest.

In an admin terminal window I did py -m pip install -U pytest-cov.

In a user terminal window I did py -m pytest -x --capture=sys debug_tools\symbol_test.py.

Versions

> ver
Microsoft Windows [Version 10.0.19042.868]

> py --version
Python 3.9.2

> pytest --version
pytest 6.2.2

Config

I have none of these files tox.ini, pytest.ini, .coveragerc, setup.cfg .

Code

I wrote the skeleton for a unit test.

# debug_tools/symbol_test.py

from . symbol import *
import pytest
class TestValue:
    pass
class TestHexU8:
    pass
class TestHexu16:
    pass
class TestSymbol:
    pass
class TestSymbolTable:
    pass

After no response for several moments, I pressed Ctrl-C,

> py -m pytest -x --capture=sys debug_tools\symbol_test.py
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\tempfile.py", line 251, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
PermissionError: [Errno 13] Permission denied: 'C:\\Program Files\\Python39\\lib\\site-packages\\pytest_cov\\__pycache__\\tmp_b69qocx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
<snips>
  File "C:\Program Files\Python39\lib\tempfile.py", line 251, in _mkstemp_inner
    fd = _os.open(file, flags, 0o600)
KeyboardInterrupt
^C

Note:

> set T
TEMP=C:\Users\Doug\AppData\Local\Temp
TMP=C:\Users\Doug\AppData\Local\Temp

It looks like the pip install of pytest-cov did not compile the code.

djhenderson avatar Mar 22 '21 13:03 djhenderson

Well, it looks more like a pip issue to me. You could try having a "user install" of python as a workaround, eg:

image

ionelmc avatar Mar 22 '21 13:03 ionelmc

I tested with python 3.10, which is installed for my user only. The following are run in a user terminal:

> py -3.10 -m pip install -U pytest
> py -3.10 -m pip install -U pytest-cov
> cls && py -3.10 -m pytest -x --capture=sys debug_tools\symbol_test.py
================================================= test session starts =================================================
platform win32 -- Python 3.10.0a6, pytest-6.2.2, py-1.10.0, pluggy-0.13.1
rootdir: D:\Users\Doug\dosprogs\DebugFix
plugins: cov-2.11.1
collected 0 items

================================================ no tests ran in 0.08s ================================================

This works correctly. This is the second run, the last line of the first line was something like = no tests ran in 3.60s =.

I ran in an admin console:

py -3.9 -m pip install -U pytest-cov
py -3.9 -m pytest -x --capture=sys debug_tools\symbol_test.py

In a user terminal, I ran: py -3.9 -m pytest -x --capture=sys debug_tools\symbol_test.py

This now runs successfully.

This is the first package I have encountered that has this kind of problem.

djhenderson avatar Mar 22 '21 14:03 djhenderson

See also this bug report on StackOverflow: https://stackoverflow.com/questions/59043307/python-pytest-hangs-for-instance-pytest-version-simply-hangs

Even a simple pytest --version is hanging.

I can still reproduce this behavior on Windows 10 with Python 3.9 and 3.10. I also tried to uninstall pytest-cov.


Strangely, it works fine if executed within PyCharm !

Paebbels avatar Dec 21 '21 10:12 Paebbels