Giter Site home page Giter Site logo

Comments (16)

remort avatar remort commented on June 14, 2024 23

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.

sylvain-ri avatar sylvain-ri commented on June 14, 2024 4

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.

blueyed avatar blueyed commented on June 14, 2024 3

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.

junaruga avatar junaruga commented on June 14, 2024 1

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.

sylvain-ri avatar sylvain-ri commented on June 14, 2024 1

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.

ionelmc avatar ionelmc commented on June 14, 2024

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.

blueyed avatar blueyed commented on June 14, 2024

And that's not covered by [paths] source = X and/or [run] source = X?

from pytest-cov.

ionelmc avatar ionelmc commented on June 14, 2024

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.

codingjoe avatar codingjoe commented on June 14, 2024

👍 same here

from pytest-cov.

ionelmc avatar ionelmc commented on June 14, 2024

@codingjoe are you having the same issue or you're waiting too on some example that reproduces the issue? 😁

from pytest-cov.

codingjoe avatar codingjoe commented on June 14, 2024

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.

ionelmc avatar ionelmc commented on June 14, 2024

@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.

codingjoe avatar codingjoe commented on June 14, 2024

I can't even recreate the issue myself. So no, sorry.

from pytest-cov.

ionelmc avatar ionelmc commented on June 14, 2024

Do we have a bug report for this in https://bitbucket.org/ned/coveragepy?

from pytest-cov.

blueyed avatar blueyed commented on June 14, 2024

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.

ionelmc avatar ionelmc commented on June 14, 2024

Closing this in favour of #176. Add your thoughts there if you want your usecase documented.

from pytest-cov.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.