-
-
Notifications
You must be signed in to change notification settings - Fork 438
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
No source for code: '<path to project>/config-3.py' thrown when generating report #1653
Comments
Do you have a file named config-3.py? Are you generating files like that? It's hard to offer help without more information. BTW: I recommend measuring your tests with coverage also: https://nedbatchelder.com/blog/202008/you_should_include_your_tests_in_coverage.html |
There's no file named config-3.py in my repo, and we're not generating any files of that name. |
I'm not sure how to help. If you can make a reproducible case for me, I can dig deeper. |
Here's a reproduction with bug.py def example():
import cv2 test_bug.py from bug import example
from unittest import TestCase
class ExampleTest(TestCase):
def test_example(self):
example() Run:
Report:
Not really sure what
|
I mean, I guess the workaround is you specify
|
Another option is to add this to your coverage settings (.coveragerc, etc): [run]
omit =
config.py
config-3.py The files are created in the current directory, so I don't see a way to automatically understand that they are synthetic. |
@nedbat could |
It's an interesting idea... |
Just wanted to add that I am experiencing this issue as well. I believe it's related to opencv. We are running python 3.11.9, coverage 7.22, and opencv-python 4.10.0.82 Our plan is to use omit in .coveragerc as our solution. Full conda environment
|
I can confirm that the following was a solution for us:
|
…pencv is installed before running pytest code coverage. See nedbat/coveragepy#1653 for details
* add code coverage report to SonarQube * modify unit tests so they can be run from any directory, not just the test directory * call pytest from top directory and generate code coverage report for SonarQube * fix deprecated warnings * remove blank space * install pytest-cov instead of coverage * omit config-3.py from coverage to prevent error that is caused when opencv is installed before running pytest code coverage. See nedbat/coveragepy#1653 for details
Worked for me |
For those using
|
Describe the bug
After having run
coverage
, I try to generate a report usingcoverage report -m --omit="tests/*","*__init__.py"
. No report is generated and I'm greeted with this error:No source for code: '<path to project>/config-3.py'.
This error is encountered in version: 7.2.7
To Reproduce
Python: 3.9.16
Pipenv: 2023.3.20
Coverage version: 7.2.7
Output of
coverage debug sys
:Output of
pip freeze
:Packages are managed using
pipenv
, and Python versions are managed usingpyenv
.Commands to reproduce:
pipenv lock --dev; pipenv sync --dev; pipenv run coverage run -m unittest discover; pipenv run coverage report -m --omit="tests/*","*__init__.py"
This error can also be reproduced when running
coverage
outside of thepipenv's
virtualenv (installed viapipx
).Since this project is sensitive I can't give any more information than that.
Expected behavior
A report to be shown of my test coverage.
The text was updated successfully, but these errors were encountered: