-
Notifications
You must be signed in to change notification settings - Fork 403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running pytest coverage for a specific dataset causes an error #2541
Comments
I get a completely different set of errors:
I think we need to better understand the import logic introduced by using |
Wow! This is with the same versions of packages used by our CI? |
Probably slightly different versions. To make matters more interesting, if I convert the pytest-cov logic to coverage.py, I get a third error: > coverage run --source=torchgeo.datasets.landcoverai -m pytest tests/datasets/test_landcoverai.py
ERROR: while parsing the following warning configuration:
ignore:The .*dataloader.* does not have many workers which may be a bottleneck:lightning.fabric.utilities.warnings.PossibleUserWarning:lightning
This error occurred:
Traceback (most recent call last):
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1921, in parse_warning_filter
category: Type[Warning] = _resolve_warning_category(category_)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/_pytest/config/__init__.py", line 1959, in _resolve_warning_category
m = __import__(module, None, None, [klass])
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/lightning/__init__.py", line 18, in <module>
from lightning.fabric.fabric import Fabric # noqa: E402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/lightning/fabric/__init__.py", line 30, in <module>
from lightning.fabric.fabric import Fabric # noqa: E402
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/lightning/fabric/fabric.py", line 35, in <module>
import torch
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/torch/__init__.py", line 1703, in <module>
from torch._tensor import Tensor # usort: skip
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/torch/_tensor.py", line 21, in <module>
from torch.overrides import (
...<5 lines>...
)
File "/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/torch/overrides.py", line 1754, in <module>
has_torch_function = _add_docstr(
_has_torch_function,
...<18 lines>...
""",
)
RuntimeError: function '_has_torch_function' already has a docstring
/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/coverage/inorout.py:507: CoverageWarning: Module torchgeo.datasets.landcoverai was never imported. (module-not-imported)
self.warn(f"Module {pkg} was never imported.", slug="module-not-imported")
/Users/Adam/spack/var/spack/environments/default/.spack-env/view/lib/python3.13/site-packages/coverage/control.py:860: CoverageWarning: No data was collected. (no-data-collected)
self._warn("No data was collected.", slug="no-data-collected") |
Trying to start discussion at https://discuss.python.org/t/how-to-run-coverage-for-specific-file/46019/5 before opening an issue on GitHub since reproducing is complicated at best. |
Upgraded my environment with newer versions of everything and now I get the same error as you. |
Not sure if this is torchgeo or pytest-cov or torchvision specific but recording it here.
Our docs show an example of measuring test coverage for a specific file:
pytest --cov=torchgeo.datasets.foo tests/datasets/test_foo.py
, however if I run this (e.g.pytest --cov=torchgeo.datasets.landcoverai tests/datasets/test_landcoverai.py
then I get the following ImportError:Weirdly,
pytest --cov=torchgeo.datasets tests/datasets/test_landcoverai.py
works just fine.Also, I'll note that the initial command definitely worked at some point in time, and it works with a decently old environment that had torchvision 0.15 installed.
Shout out to @amritagupta for the initial report, thanks!
The text was updated successfully, but these errors were encountered: