Skip to content
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

Coverage missing with else : continue #9246

Closed
xjing76 opened this issue Oct 28, 2021 · 1 comment
Closed

Coverage missing with else : continue #9246

xjing76 opened this issue Oct 28, 2021 · 1 comment

Comments

@xjing76
Copy link

xjing76 commented Oct 28, 2021

Coverage report will miss hits for else: continue during a for loop.

Here is a minimal reproducible example here.

python==3.8.12
pytest==5.2.1

foo.py

def foo():
    for i in range(10):
        if i < 10:
            pass
        else :
            continue
    return 5

def foo2():
    for i in range(10):
        if i == 9:
            pass
        else:
            continue
    return 5

test_foo.py

from poj.foo import foo,  foo2
def test_foo():
    assert foo() == 5
    assert foo2() == 5

both line 6 and 14 would have only 0 hit.

<?xml version="1.0" ?>
<coverage branch-rate="0" branches-covered="0" branches-valid="0" complexity="0" line-rate="0.8333" lines-covered="10" lines-valid="12" timestamp="1635453959207" version="5.2">
	<!-- Generated by coverage.py: https://coverage.readthedocs.io -->
	<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
	<sources>
		<source>/Users/jingx/Documents/tttt/poj</source>
	</sources>
	<packages>
		<package branch-rate="0" complexity="0" line-rate="0.8333" name=".">
			<classes>
				<class branch-rate="0" complexity="0" filename="__init__.py" line-rate="1" name="__init__.py">
					<methods/>
					<lines/>
				</class>
				<class branch-rate="0" complexity="0" filename="foo.py" line-rate="0.8333" name="foo.py">
					<methods/>
					<lines>
						<line hits="1" number="1"/>
						<line hits="1" number="2"/>
						<line hits="1" number="3"/>
						<line hits="1" number="4"/>
						<line hits="0" number="6"/>
						<line hits="1" number="7"/>
						<line hits="1" number="9"/>
						<line hits="1" number="10"/>
						<line hits="1" number="11"/>
						<line hits="1" number="12"/>
						<line hits="0" number="14"/>
						<line hits="1" number="15"/>
					</lines>
				</class>
			</classes>
		</package>
	</packages>
</coverage>

@xjing76
Copy link
Author

xjing76 commented Oct 28, 2021

Seems like this is covered there nedbat/coveragepy#198

@xjing76 xjing76 closed this as completed Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant