Skip to content

Instantly share code, notes, and snippets.

@mattbennett
Created June 30, 2015 19:28
Show Gist options
  • Save mattbennett/f57a5286bd77ee52651e to your computer and use it in GitHub Desktop.
Save mattbennett/f57a5286bd77ee52651e to your computer and use it in GitHub Desktop.
coverage.py exec
def foo():
print "foo"
def bar():
print "bar"
print "the answer to life, the universe and everything is: {}".format(undeclared_var)
from impl import foo
foo()
namespace = {
'undeclared_var': 42
}
with open('impl2.py') as f:
code = compile(f.read(), 'impl2.py', 'exec')
exec(code, globals(), namespace)
@mattbennett
Copy link
Author

$ coverage run --source . test.py
foo
the answer to life, the universe and everything is: 42
$ coverage report
Name    Stmts   Miss  Cover
---------------------------
impl        4      1    75%
impl2       1      1     0%
test        6      0   100%
---------------------------
TOTAL      11      2    82%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment