I've been working on a PR for rpy2 package to improve its support for Windows, and I cannot figure out how to debug the pytest-cov/coverage related issue on a test.
Here is the link to my folk for the test, which only hangs in Windows (passes GitHub Action with Ubuntu & MacOS). Eliminating irrelevant options, the minimal pytest command is:
#!/bin/bash
pytest \
--cov=rpy2.robjects.lib \
rpy2/tests/robjects/lib
and it hangs after printing
============================================= test session starts ==============================================
platform win32 -- Python 3.9.7, pytest-7.1.2, pluggy-1.0.0
rootdir: C:\Users\tikum\Documents\Python\rpy2
plugins: cov-3.0.0
collecting ...
Debugging the pytest execution, I can follow up until it reaches coverage.py's Collector._start_tracer() (collector.py Line 278):
fn = tracer.start()
I basically run out of ideas at this point on what to do. Can anyone point me in the right direction on what to look for to resolve this issue?
Versions:
coverage 6.4.1
pytest 7.1.2
pytest-cov 3.0.0
Related
When I run my pytest in pipenv shell I get this:
pipenv shell
Loading .env environment variables…
Launching subshell in virtual environment…
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ . /Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/bin/activate
(kittycapital) bash-3.2$ python -m pytest
============================================================================================================================= test session starts ==============================================================================================================================
platform darwin -- Python 3.7.7, pytest-5.4.3, py-1.9.0, pluggy-0.13.1
rootdir: /Users/.../kittycapital
plugins: mock-3.1.1
collected 4 items
tests/test_account.py . [ 25%]
tests/test_pair.py .. [ 75%]
tests/helpers/test_number_helpers.py . [100%]
=============================================================================================================================== warnings summary ===============================================================================================================================
/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/util/selectors.py:14
/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/util/selectors.py:14: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
from collections import namedtuple, Mapping
/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/_collections.py:2
/Users/.../.local/share/virtualenvs/kittycapital-UOiJxZhy/lib/python3.7/site-packages/urllib3/_collections.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working
from collections import Mapping, MutableMapping
-- Docs: https://docs.pytest.org/en/latest/warnings.html
How do I get rid of these warnings?
Either upgrade your dependencies to versions that do not trigger warnings, or put this in pytest.ini to hide that warning:
[pytest]
filterwarnings = ignore:.*Using or importing the ABCs.*is deprecated:DeprecationWarning
See https://docs.pytest.org/en/stable/warnings.html#deprecationwarning-and-pendingdeprecationwarning
Or use the --disable-warnings flag to hide all warnings:
python -m pytest --disable-warnings
See https://docs.pytest.org/en/stable/warnings.html#disabling-warnings-summary
I’m pretty new to contributing to open source projects and am trying to get some coverage reports so I can find out what needs more / better testing. However, I am having trouble getting the full coverage of a test. This is for pytorch
For example, lets say I want to get the coverage report of test_indexing_py.
I run the command:
pytest test_indexing.py --cov=../ --cov-report=html
Resulting in this:
================================================= test session starts =================================================
platform win32 -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: C:\Projects\pytorch
plugins: hypothesis-5.4.1, arraydiff-0.3, cov-2.8.1, doctestplus-0.4.0, openfiles-0.4.0, remotedata-0.3.2
collected 62 items
test_indexing.py ............................s................................. [100%]
----------- coverage: platform win32, python 3.7.4-final-0 -----------
Coverage HTML written to dir htmlcov
=========================================== 61 passed, 1 skipped in 50.43s ============================================
Ok, looks like the tests ran. Now when I check the html coverage report, I only get the coverage for the test file and not for the classes tested (the tests are ordered by coverage percentage).
As you can see, I am getting coverage for only test_indexing.py. How do I get the full coverage report including the classes tested?
Any guidance will be greatly appreciated.
I think its because you are asking to check the coverage from the test running directory, ie where test_indexing.py is.
A better approach would be like running the test from the root directory itself, rather than test directory, it has several advantages like the configuration file reading and all.
And regarding your question, try running the test from the root directory and try
pytest path/to/test/ --cov --cov-report=html
pytest seems to be ignoring tests that use PySide.
For example, I have a file test_pyside.py with the contents
from PySide import QtGui
def test_dialog():
dialog = QtGui.QDialog()
assert False
The output for running python -m pytest test_pyside.py is:
============================ test session starts ============================
platform win32 -- Python 2.7.12, pytest-3.0.5, py-1.4.31, pluggy-0.4.0 rootdir: C:\Users\erik, inifile:
collected 1 items
That's it. No Error report. I don't know why.
Your test segfaults because it creates a QDialog without creating a QApplication. I suggest using the pytest-qt plugin to take care of that for you.
I'm working through http://blog.thedigitalcatonline.com/blog/2015/05/13/python-oop-tdd-example-part1/#.Vw0NojFJJ9n .
When I try:
$ py.test
============================= test session starts =============================
platform win32 -- Python 3.2.5, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: C:\envs\r3\binary, inifile:
plugins: capturelog-0.7
collected 0 items / 1 errors
=================================== ERRORS ====================================
____________________ ERROR collecting tests/test_binary.py ____________________
tests\test_binary.py:3: in <module>
import Binary
E ImportError: No module named Binary
================= 1 pytest-warnings, 1 error in 0.20 seconds ==================
What am I doing wrong?
Add current directory to PYTHONPATH environmental variable.
As you are on Windows:
$ set PYTHONPATH="."
This shall help py.test to find and import the module.
Checking the py.test tutorial I see, that at "Writing the class" section they use exactly the same trick.
In practice, you do not have to do this, as you usually test against installed Python module (typically with setup.py in project root directory and using develop mode), and it is accessible for import easily without playing with PYTHONPATH.
I've a problem unit testing Python code, which uses the (py)ROOT package. It simply aborts collecting the tests when there is a line import ROOT in one of the scripts.
Does anybody have an idea what's going on?
foo#bar ~/project/dir [19:21:17]
(project)> $ py.test -v [±master ●]
============================= test session starts ==============================
platform darwin -- Python 2.7.6 -- py-1.4.25 -- pytest-2.6.3 -- /path/to/.virtualenvs/project/bin/python
collecting 0 items[1] 16520 abort py.test -v
I had a similar issue by adding the PyROOT bindings to export $PYTHONPATH in my .bashrc. The locally set PYTHONPATH was ignored. A solution is copying or linking the ROOT.py and libPyROOT.so files to the appropriate Python directory in /usr/lib. More details in this answer: https://stackoverflow.com/a/33130000/4753851