Skip to content

Commit

Permalink
A test for #909
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jan 3, 2020
1 parent 016af5f commit 7541b4f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tests/test_process.py
Expand Up @@ -1004,6 +1004,34 @@ def test_coverage_custom_script(self):
out = self.run_command("python -m run_coverage run how_is_it.py")
self.assertIn("hello-xyzzy", out)

def test_bug_909(self):
# https://github.com/nedbat/coveragepy/issues/909
# The __init__ files were being imported before measurement started,
# so the line in __init__.py was being marked as missed, and there were
# warnings about measured files being imported before start.
self.make_file("proj/__init__.py", "print('Init')")
self.make_file("proj/thecode.py", "print('The code')")
self.make_file("proj/tests/__init__.py", "")
self.make_file("proj/tests/test_it.py", "import proj.thecode")

expected = "Init\nThe code\n"
actual = self.run_command("coverage run --source=proj -m proj.tests.test_it")
assert expected == actual

report = self.run_command("coverage report -m")

# Name Stmts Miss Cover Missing
# ------------------------------------------------------
# proj/__init__.py 1 0 100%
# proj/tests/__init__.py 0 0 100%
# proj/tests/test_it.py 1 0 100%
# proj/thecode.py 1 0 100%
# ------------------------------------------------------
# TOTAL 3 0 100%

squeezed = self.squeezed_lines(report)
assert squeezed[2].replace("\\", "/") == "proj/__init__.py 1 0 100%"


class ExcepthookTest(CoverageTest):
"""Tests of sys.excepthook support."""
Expand Down

0 comments on commit 7541b4f

Please sign in to comment.