Comments (16)
Problem with modules placed in dirs without init files is still exists, while
#176 is closed.
The bug is still exists. In python 3 modules (.py files) doesn't need init files be placed nearby to be able code from these files to be imported. I don't use init files and always import code directly from .py files. The whole lotta applications written without init files and pytest do not cover such dirs (if code from files is not imported or tested somehow in tests runned by pytest).
from pytest-cov.
For people also ending here, there is the solution:
add a config file for your pytest-cov command pytest --cov=<folder> --cov-config=.coverage_rc
Content of .coverage_rc
[report]
include_namespace_packages = true
# might also be convenient to add one of these:
omit = **/__init__.py
skip_empty = true
Adapt the heading to [tool.coverage.report]
if within a pyproject.toml file
from pytest-cov.
This happens because of a missing __init__.py
file.
coveragepy skips it then (https://github.com/nedbat/coveragepy/blob/e7c532c2dbcef6281df5a7a0db53eca4083a026a/coverage/files.py#L342-L346).
This gets used in Coverage.get_data
(https://github.com/nedbat/coveragepy/blob/e7c532c2dbcef6281df5a7a0db53eca4083a026a/coverage/control.py#L823-L831).
I think that also "non-importable" files should be included - but that is an issue to raise for coveragepy then probably?!
In my case the __init__.py
file was missing in project/app/management/__init__.py
, but that is no problem for Django itself - the commands can be used.
(Maybe that's because project/app/management/commands/__init__.py
exists?!)
from pytest-cov.
Though I am not sure my case is same case with this report.
I was succeeded to report files in directory without __init__.py
in my case.
$ cat .coveragerc
# https://coverage.readthedocs.io/en/latest/config.html
[run]
include =
rpm_py_installer/*
install.py
setup.py
$ pytest --cov-config .coveragerc --cov . tests
...
Name Stmts Miss Cover
--------------------------------------------------
install.py 325 27 92% <=== This file is not in __init__.py's directory, and reported here.
rpm_py_installer/__init__.py 0 0 100%
rpm_py_installer/version.py 1 0 100%
setup.py 35 35 0%
--------------------------------------------------
TOTAL 361 62 83%
See rpm-py-installer/rpm-py-installer#59 for detail.
from pytest-cov.
The current solution is to use include_namespace_packages = True
https://coverage.readthedocs.io/en/7.0.0/config.html#report-include-namespace-packages
from pytest-cov.
This feature is built into coverage, but with a caveat: you have to use paths for the source.
Eg: if you use py.test --cov=somepath
then you'll get all files in somepath
in the report.
from pytest-cov.
And that's not covered by [paths] source = X
and/or [run] source = X
?
from pytest-cov.
Not really sure, but it sounds like it's not something pytest-cov specific. What behavior do you get if you use plain coverage (eg: coverage run -mpytest tests
)?
If you put an example somewhere I'll take a look.
from pytest-cov.
👍 same here
from pytest-cov.
@codingjoe are you having the same issue or you're waiting too on some example that reproduces the issue? 😁
from pytest-cov.
Never mind problem gone. I had the same problem too, but only once. Now it's gone, very curious. Made my coverage skyrocket. Now it's back to "normal".
from pytest-cov.
@blueyed Can you create some minimal project that reproduce the issue? Or at least point to the project that has this problem ...
from pytest-cov.
I can't even recreate the issue myself. So no, sorry.
from pytest-cov.
Do we have a bug report for this in https://bitbucket.org/ned/coveragepy?
from pytest-cov.
I could not find one, and given the comment in https://github.com/nedbat/coveragepy/blob/d5a89ab843542f88544a0f55900093329ef6b85c/coverage/files.py#L331-L346 it might even be not possible?!
from pytest-cov.
Closing this in favour of #176. Add your thoughts there if you want your usecase documented.
from pytest-cov.
Related Issues (20)
- Issue with coverage[toml] when installing with require-hashes. HOT 3
- PyO3 error HOT 1
- cov-config file argument ignored when tox.ini exists HOT 1
- [docs] Delete AppVeyor mentions
- [docs] Merge overview/readme and index documents in Sphinx
- [docs] Switch to Furo
- [FR] Extend pytest mark/fixture to auto-apply `# pragma: no cover`
- Pytest and pytest-cov reload numpy HOT 1
- Remove usage of deprecated `rsyncdir`, which will be removed in pytest-xdist 4.0 HOT 2
- Ignore partial lines in the coverage report percentage HOT 3
- Strange BSD License mapping for pytest_cov-2.7.1-py2.py3-none-any.whl HOT 1
- no-data-collected under unix when using filterwarnings in pytest.ini HOT 4
- Memory Leak Python 3.12.2 HOT 13
- GitHub Actions failures on Python 3.8 and 3.9 on pytest81-xdist350-coverage74 (windows) HOT 1
- coverage starts too late when a plugin imports the project under test HOT 5
- "Fail under check" is failing because of ignoring the precession config
- Pytest-watch with coverage (If not existent)
- Coverage both says its 100% and 0% when no code lines are found, fails
- Error combining coverage when running with pytest-xdist and a custom coverage plugin HOT 3
- condition was never false HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytest-cov.