py.builtin.exec_ => six.exec_
This commit is contained in:
parent
0fc4a806e5
commit
c2cd337886
|
@ -1,4 +1,4 @@
|
||||||
import py
|
import six
|
||||||
|
|
||||||
for i in range(1000):
|
for i in range(1000):
|
||||||
py.builtin.exec_("def test_func_%d(): pass" % i)
|
six.exec_("def test_func_%d(): pass" % i)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import py
|
import six
|
||||||
|
|
||||||
|
|
||||||
def otherfunc(a, b):
|
def otherfunc(a, b):
|
||||||
|
@ -177,7 +177,7 @@ def test_dynamic_compile_shows_nicely():
|
||||||
name = "abc-123"
|
name = "abc-123"
|
||||||
module = imp.new_module(name)
|
module = imp.new_module(name)
|
||||||
code = _pytest._code.compile(src, name, "exec")
|
code = _pytest._code.compile(src, name, "exec")
|
||||||
py.builtin.exec_(code, module.__dict__)
|
six.exec_(code, module.__dict__)
|
||||||
sys.modules[name] = module
|
sys.modules[name] = module
|
||||||
module.foo()
|
module.foo()
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ from weakref import ref
|
||||||
from _pytest.compat import _PY2, _PY3, PY35, safe_str
|
from _pytest.compat import _PY2, _PY3, PY35, safe_str
|
||||||
from six import text_type
|
from six import text_type
|
||||||
import py
|
import py
|
||||||
|
import six
|
||||||
|
|
||||||
builtin_repr = repr
|
builtin_repr = repr
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ class Frame(object):
|
||||||
"""
|
"""
|
||||||
f_locals = self.f_locals.copy()
|
f_locals = self.f_locals.copy()
|
||||||
f_locals.update(vars)
|
f_locals.update(vars)
|
||||||
py.builtin.exec_(code, self.f_globals, f_locals)
|
six.exec_(code, self.f_globals, f_locals)
|
||||||
|
|
||||||
def repr(self, object):
|
def repr(self, object):
|
||||||
""" return a 'safe' (non-recursive, one-line) string repr for 'object'
|
""" return a 'safe' (non-recursive, one-line) string repr for 'object'
|
||||||
|
|
|
@ -223,7 +223,7 @@ class AssertionRewritingHook(object):
|
||||||
mod.__loader__ = self
|
mod.__loader__ = self
|
||||||
# Normally, this attribute is 3.4+
|
# Normally, this attribute is 3.4+
|
||||||
mod.__spec__ = spec_from_file_location(name, co.co_filename, loader=self)
|
mod.__spec__ = spec_from_file_location(name, co.co_filename, loader=self)
|
||||||
py.builtin.exec_(co, mod.__dict__)
|
six.exec_(co, mod.__dict__)
|
||||||
except: # noqa
|
except: # noqa
|
||||||
if name in sys.modules:
|
if name in sys.modules:
|
||||||
del sys.modules[name]
|
del sys.modules[name]
|
||||||
|
|
|
@ -4,7 +4,7 @@ import sys
|
||||||
from numbers import Number
|
from numbers import Number
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
import py
|
import six
|
||||||
from six.moves import zip, filterfalse
|
from six.moves import zip, filterfalse
|
||||||
from more_itertools.more import always_iterable
|
from more_itertools.more import always_iterable
|
||||||
|
|
||||||
|
@ -680,8 +680,8 @@ def raises(expected_exception, *args, **kwargs):
|
||||||
# print "raises frame scope: %r" % frame.f_locals
|
# print "raises frame scope: %r" % frame.f_locals
|
||||||
try:
|
try:
|
||||||
code = _pytest._code.Source(code).compile()
|
code = _pytest._code.Source(code).compile()
|
||||||
py.builtin.exec_(code, frame.f_globals, loc)
|
six.exec_(code, frame.f_globals, loc)
|
||||||
# XXX didn'T mean f_globals == f_locals something special?
|
# XXX didn't mean f_globals == f_locals something special?
|
||||||
# this is destroyed here ...
|
# this is destroyed here ...
|
||||||
except expected_exception:
|
except expected_exception:
|
||||||
return _pytest._code.ExceptionInfo()
|
return _pytest._code.ExceptionInfo()
|
||||||
|
|
|
@ -4,11 +4,11 @@ from __future__ import absolute_import, division, print_function
|
||||||
import inspect
|
import inspect
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import py
|
import re
|
||||||
import sys
|
import sys
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import re
|
import six
|
||||||
|
|
||||||
from _pytest.fixtures import yield_fixture
|
from _pytest.fixtures import yield_fixture
|
||||||
from _pytest.outcomes import fail
|
from _pytest.outcomes import fail
|
||||||
|
@ -130,7 +130,7 @@ def warns(expected_warning, *args, **kwargs):
|
||||||
|
|
||||||
with WarningsChecker(expected_warning, match_expr=match_expr):
|
with WarningsChecker(expected_warning, match_expr=match_expr):
|
||||||
code = _pytest._code.Source(code).compile()
|
code = _pytest._code.Source(code).compile()
|
||||||
py.builtin.exec_(code, frame.f_globals, loc)
|
six.exec_(code, frame.f_globals, loc)
|
||||||
else:
|
else:
|
||||||
func = args[0]
|
func = args[0]
|
||||||
with WarningsChecker(expected_warning, match_expr=match_expr):
|
with WarningsChecker(expected_warning, match_expr=match_expr):
|
||||||
|
|
|
@ -6,8 +6,8 @@ import inspect
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
import py
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import six
|
||||||
from _pytest._code import Source
|
from _pytest._code import Source
|
||||||
from _pytest._code.source import ast
|
from _pytest._code.source import ast
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ class TestSourceParsingAndCompiling(object):
|
||||||
|
|
||||||
def test_compile_and_getsource(self):
|
def test_compile_and_getsource(self):
|
||||||
co = self.source.compile()
|
co = self.source.compile()
|
||||||
py.builtin.exec_(co, globals())
|
six.exec_(co, globals())
|
||||||
f(7)
|
f(7)
|
||||||
excinfo = pytest.raises(AssertionError, "f(6)")
|
excinfo = pytest.raises(AssertionError, "f(6)")
|
||||||
frame = excinfo.traceback[-1].frame
|
frame = excinfo.traceback[-1].frame
|
||||||
|
@ -392,7 +392,7 @@ def test_getfuncsource_dynamic():
|
||||||
def g(): pass
|
def g(): pass
|
||||||
"""
|
"""
|
||||||
co = _pytest._code.compile(source)
|
co = _pytest._code.compile(source)
|
||||||
py.builtin.exec_(co, globals())
|
six.exec_(co, globals())
|
||||||
assert str(_pytest._code.Source(f)).strip() == "def f():\n raise ValueError"
|
assert str(_pytest._code.Source(f)).strip() == "def f():\n raise ValueError"
|
||||||
assert str(_pytest._code.Source(g)).strip() == "def g(): pass"
|
assert str(_pytest._code.Source(g)).strip() == "def g(): pass"
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import textwrap
|
||||||
import zipfile
|
import zipfile
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
import six
|
||||||
|
|
||||||
import _pytest._code
|
import _pytest._code
|
||||||
from _pytest.assertion import util
|
from _pytest.assertion import util
|
||||||
|
@ -49,7 +50,7 @@ def getmsg(f, extra_ns=None, must_pass=False):
|
||||||
ns = {}
|
ns = {}
|
||||||
if extra_ns is not None:
|
if extra_ns is not None:
|
||||||
ns.update(extra_ns)
|
ns.update(extra_ns)
|
||||||
py.builtin.exec_(code, ns)
|
six.exec_(code, ns)
|
||||||
func = ns[f.__name__]
|
func = ns[f.__name__]
|
||||||
try:
|
try:
|
||||||
func()
|
func()
|
||||||
|
|
Loading…
Reference in New Issue