Comments (18)
Hi all, sorry for the regression. I'm working on a fix. The code uses tokenize to analyze the code, which isn't holding up well. I'm working on switching it to use the AST instead.
from coveragepy.
This is now released as part of coverage 7.3.4.
from coveragepy.
Here is a test for the test suite that demonstrates the problem:
@ tests/test_coverage.py:1743 @ def my_func_2(super_long_input_argument_0=0, super_long_input_argument_1=1, supe
[], "5", excludes=['my_func']
)
+ def test_excluding_clause_bug1713(self) -> None:
+ self.check_coverage("""\
+ print("1")
+
+ def hello_3(a): # no thanks
+ if ("4" or
+ "5"):
+ print("6")
+ else:
+ print("8")
+
+ print("10")
+ """,
+ [1, 10], "", excludes=["no thanks"],
+ )
+
def test_excluding_method(self) -> None:
self.check_coverage("""\
class Fooey:
@kajakaj, @maciekgyver, do you have an idea how to handle this case?
from coveragepy.
We have seen this regression for a class as well, so seems like anything block level.
class Foo: # pragma: no cover
def greet(self):
print("hello world")
from coveragepy.
I am also seeing a regression in coverage (only in CI though?) for a case like:
class MyClass: # pragma: no cover
def method(self):
pass
Which was previously ignoring the lines in method()
, but is now failing for missing coverage.
from coveragepy.
Just to make it clear, the case in the issue description was run on Linux.
from coveragepy.
Not sure if related, but I also have a new coverage miss on coverage 7.3.3
Code:
if condition_a: # pragma: no cover; local only
func1()
if (
condition_b
== 0
):
return
func2() # this statement is now shown as not covered
On prior versions, the whole if block was ignored correctly.
from coveragepy.
Not sure this is exactly the same problem, but in case it helps, we're also seeing a regression in the Briefcase test suite. However, we're only seeing it on Windows. I'll try to reduce this to a simple reproduction case.
from coveragepy.
I haven't narrowed this down to a specific reproduction case yet, but it appears to be related to an interaction with coverage-conditional-plugin. This is the coverage file for the failing run; it has 100% coverage on coverage 7.3.2, but has the 2 missing blocks of lines on coverage 7.3.3, (conditional-coverage-plugin=0.9.0), with a conditional rule of no-cover-if-is-windows = True
defined.
from coveragepy.
FWIW: The pattern that @ringohoffman has described is very similar to what is happening in my case; however, I haven't been able to generate a simple reproduction case that fails.
In case it helps someone else: in my case, the no cover
is conditional on a sys.platform
check. The failure only occurs on Windows; the coverage reports missing lines on Windows, as well as when the Windows report is combined with a Linux and macOS report (Linux and macOS both do have coverage of the given lines).
The code that is being mistakenly marked as a coverage miss is:
- a method in a class where the entire class is marked
no-cover
- 2 context manager blocks one after another inside a method of a class, where the method is marked no-cover.
The second one is particularly odd, because there's plenty of other lines in the method (both before and after the problematic context managers) that are marked as covered, as well as other context managers in the same method.
from coveragepy.
We are also combining Linux and Windows reports, so the bug could indeed be related to Windows.
Although as you can see from my example above it doesn't have to be a class, it can be any kind of nested block (an if
statement in my case).
from coveragepy.
Another occurrence, which was quite confusing: I have several classes in one file, inheriting after abstract and all individually marked with pragma: no cover
, yet several classes did not trigger anything, one triggered errors for all its @property
, while two classes later one method was included in coverage with __init__
and @property
elements of the said class ignored as expected.
Go figure. Code is in private repository, but I can look for potential triggers of this behaviour, if directed.
The first class has multiline definition of __init__
, the final error comes from a method that has multiline for
, BUT the preceding method has multiline for
as well, so maybe the first is used as a trigger, the other gets the error? Only these two multiline for
are in this file and one multiline __init__
declaration.
My case, somewhat simplified:
class BreakingInit: # pragma: no cover
def __init__(
self, absurdly_long_argument_name_to_break_definition_here: int, another_long_argument_name: str
) -> None:
self._number = absurdly_long_argument_name_to_break_definition_here
self._string = another_long_argument_name
@property
def number(self) -> int:
return self._number
@property
def string(self) -> str:
return self._string
class BreakingFor: # pragma: no cover
def __init__(self, just_an_argument: str) -> None:
self._string = just_an_argument
def get_all_spaces(self) -> str:
spaces = ""
for number, character in enumerate(
self._string
):
if character == " ":
spaces += character
return spaces
def get_all_non_spaces(self) -> str:
non_spaces = ""
for number, character in enumerate(
self._string
):
if character != " ":
non_spaces += character
return non_spaces
Results:
BreakingInit
first:9-39
(starts after__init__
)BreakingFor
first:13-39
(starts on the first instruction afterfor
)
No idea how to reproduce the "fix" yet (as in, how to add methods that are still excluded from the final coverage and in between erroneous blocks); I tried adding another class in between, did not change behaviour to the one observed.
from coveragepy.
I've made a simple fix on the nedbat/bug1713 branch. BUT: only one of the examples shown in the comments here (the match/case in the original description) was broken for me in 7.3.3. I don't see why there would be an OS sensitivity in either the original bug or the fix.
To try the fixed code:
python3 -m pip install git+https://github.com/nedbat/coveragepy@e406af2ac00dfcf7f#egg=coverage==0.0
Please let me know what you find.
from coveragepy.
@nedbat Can confirm that branch seems to address the problem for me. Thanks for the fast turnaround under very obscure reproduction circumstances :-)
from coveragepy.
@nedbat Can confirm that branch seems to address the problem for me. Thanks for the fast turnaround under very obscure reproduction circumstances :-)
Thanks for the confirmation, but it kind of just deepens the mystery...
from coveragepy.
I can confirm this fixes the issue for my reported sample (e406af2)
from coveragepy.
This is fixed in commit 07b76b2.
from coveragepy.
I can confirm that the match..case
from which I made the minimal example for the issue description works OK on master. Thanks for the fix :-).
from coveragepy.
Related Issues (20)
- coverage report might raise FileNotFoundError when test patches glob HOT 3
- Can we add a json schema to complete pyproject.toml's [tool.coverage]?
- Test suite gets stuck when running on Windows PyPy 7.3.15 HOT 11
- test suite gets really slow in pypy3.9-v7.3.15 on ubuntu 22.04.3 HOT 4
- notes on our experience upgrading coverage 5.4 -> 7.4 HOT 1
- Question: Can `no-cover` "cover" the rest of the function? HOT 2
- Question: How to get the coverage data for each incoming request on my web server. HOT 2
- "No data was collected" when passing --source containing new line separated list HOT 5
- Question: how to add a middleware located on a different folder in settings.py ? HOT 1
- How to exclude external packages from coverage report when using coverage.py API ? HOT 1
- Use PEP 669 Low Impact Monitoring to reduce overhead HOT 3
- How to automate a coverage report using .coveragerc file HOT 1
- How to only show functions that hasn't been covered? HOT 1
- Relative paths duplicates paths on Windows HOT 9
- Facing issue No source for code while combining multiple coverage files HOT 5
- Exclude_lines unable to exclude entire if block from coverage.py in 5.5 version. HOT 5
- Option to record and report classes and imports not used at runtime HOT 1
- Current approach to restarting data collection? HOT 1
- Want to get coverage for 3rd party dependencies' code used by my project. HOT 9
- Coverage html complains about parsing Aenum's _py2.py HOT 6
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 coveragepy.