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

Ensure rewritten modules don't inherit __future__ flags from pytest #2350

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def _rewrite_test(config, fn):
return None, None
rewrite_asserts(tree, fn, config)
try:
co = compile(tree, fn.strpath, "exec")
co = compile(tree, fn.strpath, "exec", dont_inherit=True)
except SyntaxError:
# It's possible that this error is from some bug in the
# assertion rewriting, but I don't know of a fast way to tell.
Expand Down
18 changes: 18 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,24 @@ def test():
result.stdout.fnmatch_lines(['*= 1 passed in *=*'])
assert 'pytest-warning summary' not in result.stdout.str()

@pytest.mark.skipif(sys.version_info[0] > 2, reason='python 2 only')
def test_rewrite_future_imports(self, testdir):
"""Test that rewritten modules don't inherit the __future__ flags
from the assertrewrite module.

assertion.rewrite imports __future__.division (and others), so
ensure rewritten modules don't inherit those flags.

The test below will fail if __future__.division is enabled
"""
testdir.makepyfile('''
def test():
x = 1 / 2
assert type(x) is int
''')
result = testdir.runpytest()
assert result.ret == 0


class TestAssertionRewriteHookDetails(object):
def test_loader_is_package_false_for_module(self, testdir):
Expand Down