add a way to disable assertion rewriting for a module
This commit is contained in:
parent
993efe927b
commit
76cede83c0
|
@ -98,7 +98,11 @@ class AssertionRewriter(ast.NodeVisitor):
|
|||
for item in mod.body:
|
||||
if (expect_docstring and isinstance(item, ast.Expr) and
|
||||
isinstance(item.value, ast.Str)):
|
||||
lineno += len(item.value.s.splitlines()) - 1
|
||||
doc = item.value.s
|
||||
if "PYTEST_DONT_REWRITE" in doc:
|
||||
# The module has disabled assertion rewriting.
|
||||
return
|
||||
lineno += len(doc) - 1
|
||||
expect_docstring = False
|
||||
elif (not isinstance(item, ast.ImportFrom) or item.level > 0 and
|
||||
item.identifier != "__future__"):
|
||||
|
|
|
@ -76,6 +76,14 @@ class TestAssertionRewrite:
|
|||
assert imp.col_offset == 0
|
||||
assert isinstance(m.body[5], ast.Expr)
|
||||
|
||||
def test_dont_rewrite(self):
|
||||
s = """'PYTEST_DONT_REWRITE'\nassert 14"""
|
||||
m = rewrite(s)
|
||||
assert len(m.body) == 2
|
||||
assert isinstance(m.body[0].value, ast.Str)
|
||||
assert isinstance(m.body[1], ast.Assert)
|
||||
assert m.body[1].msg is None
|
||||
|
||||
def test_name(self):
|
||||
def f():
|
||||
assert False
|
||||
|
|
Loading…
Reference in New Issue