Deprecate raises(..., 'code(as_a_string)') / `warns(..., 'code(as_a_string)')
This commit is contained in:
@@ -6,6 +6,7 @@ from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
|
||||
import ast
|
||||
import inspect
|
||||
import sys
|
||||
|
||||
@@ -14,7 +15,6 @@ import six
|
||||
import _pytest._code
|
||||
import pytest
|
||||
from _pytest._code import Source
|
||||
from _pytest._code.source import ast
|
||||
|
||||
|
||||
astonly = pytest.mark.nothing
|
||||
@@ -306,8 +306,6 @@ class TestSourceParsingAndCompiling(object):
|
||||
pytest.raises(SyntaxError, lambda: source.getstatementrange(0))
|
||||
|
||||
def test_compile_to_ast(self):
|
||||
import ast
|
||||
|
||||
source = Source("x = 4")
|
||||
mod = source.compile(flag=ast.PyCF_ONLY_AST)
|
||||
assert isinstance(mod, ast.Module)
|
||||
@@ -317,10 +315,9 @@ class TestSourceParsingAndCompiling(object):
|
||||
co = self.source.compile()
|
||||
six.exec_(co, globals())
|
||||
f(7)
|
||||
excinfo = pytest.raises(AssertionError, "f(6)")
|
||||
excinfo = pytest.raises(AssertionError, f, 6)
|
||||
frame = excinfo.traceback[-1].frame
|
||||
stmt = frame.code.fullsource.getstatement(frame.lineno)
|
||||
# print "block", str(block)
|
||||
assert str(stmt).strip().startswith("assert")
|
||||
|
||||
@pytest.mark.parametrize("name", ["", None, "my"])
|
||||
@@ -361,17 +358,13 @@ def test_getline_finally():
|
||||
def c():
|
||||
pass
|
||||
|
||||
excinfo = pytest.raises(
|
||||
TypeError,
|
||||
"""
|
||||
teardown = None
|
||||
try:
|
||||
c(1)
|
||||
finally:
|
||||
if teardown:
|
||||
teardown()
|
||||
""",
|
||||
)
|
||||
with pytest.raises(TypeError) as excinfo:
|
||||
teardown = None
|
||||
try:
|
||||
c(1)
|
||||
finally:
|
||||
if teardown:
|
||||
teardown()
|
||||
source = excinfo.traceback[-1].statement
|
||||
assert str(source).strip() == "c(1)"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user