Moved py.code code over to py.test

Fix #103
This commit is contained in:
Bruno Oliveira
2015-11-27 12:43:01 -02:00
parent ed3c96ee58
commit a912d3745b
45 changed files with 4559 additions and 158 deletions

View File

@@ -81,13 +81,10 @@ and if you need to have access to the actual exception info you may use::
f()
assert 'maximum recursion' in str(excinfo.value)
``excinfo`` is a `py.code.ExceptionInfo`_ instance, which is a wrapper around
``excinfo`` is a ``ExceptionInfo`` instance, which is a wrapper around
the actual exception raised. The main attributes of interest are
``.type``, ``.value`` and ``.traceback``.
.. _py.code.ExceptionInfo:
http://pylib.readthedocs.org/en/latest/code.html#py-code-exceptioninfo
If you want to write test code that works on Python 2.4 as well,
you may also use two other ways to test for an expected exception::

View File

@@ -1,4 +1,5 @@
from pytest import raises
import _pytest._code
import py
def otherfunc(a,b):
@@ -159,7 +160,7 @@ def test_dynamic_compile_shows_nicely():
src = 'def foo():\n assert 1 == 0\n'
name = 'abc-123'
module = py.std.imp.new_module(name)
code = py.code.compile(src, name, 'exec')
code = _pytest._code.compile(src, name, 'exec')
py.builtin.exec_(code, module.__dict__)
py.std.sys.modules[name] = module
module.foo()

View File

@@ -4,6 +4,7 @@ serialization via the pickle module.
"""
import py
import pytest
import _pytest._code
pythonlist = ['python2.6', 'python2.7', 'python3.3']
@pytest.fixture(params=pythonlist)
@@ -23,7 +24,7 @@ class Python:
self.picklefile = picklefile
def dumps(self, obj):
dumpfile = self.picklefile.dirpath("dump.py")
dumpfile.write(py.code.Source("""
dumpfile.write(_pytest._code.Source("""
import pickle
f = open(%r, 'wb')
s = pickle.dump(%r, f, protocol=2)
@@ -33,7 +34,7 @@ class Python:
def load_and_is_true(self, expression):
loadfile = self.picklefile.dirpath("load.py")
loadfile.write(py.code.Source("""
loadfile.write(_pytest._code.Source("""
import pickle
f = open(%r, 'rb')
obj = pickle.load(f)