merge from master

This commit is contained in:
Ronny Pfannschmidt 2016-02-05 00:10:28 +01:00
commit de1a9f574c
21 changed files with 191 additions and 122 deletions

View File

@ -71,9 +71,11 @@
.. _@The-Compiler: https://github.com/The-Compiler .. _@The-Compiler: https://github.com/The-Compiler
2.8.7.dev1
----------
2.8.7
-----
- fix #1338: use predictable object resolution for monkeypatch
2.8.6 2.8.6
----- -----

View File

@ -5,7 +5,6 @@ import re
from py.builtin import _basestring from py.builtin import _basestring
RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$") RE_IMPORT_ERROR_NAME = re.compile("^No module named (.*)$")
@ -32,62 +31,71 @@ def pytest_funcarg__monkeypatch(request):
return mpatch return mpatch
def resolve(name):
# simplified from zope.dottedname
parts = name.split('.')
used = parts.pop(0)
found = __import__(used)
for part in parts:
used += '.' + part
try:
found = getattr(found, part)
except AttributeError:
pass
else:
continue
# we use explicit un-nesting of the handling block in order
# to avoid nested exceptions on python 3
try:
__import__(used)
except ImportError as ex:
# str is used for py2 vs py3
expected = str(ex).split()[-1]
if expected == used:
raise
else:
raise ImportError(
'import error in %s: %s' % (used, ex)
)
found = annotated_getattr(found, part, used)
return found
def annotated_getattr(obj, name, ann):
try:
obj = getattr(obj, name)
except AttributeError:
raise AttributeError(
'%r object at %s has no attribute %r' % (
type(obj).__name__, ann, name
)
)
return obj
def derive_importpath(import_path, raising): def derive_importpath(import_path, raising):
import pytest
if not isinstance(import_path, _basestring) or "." not in import_path: if not isinstance(import_path, _basestring) or "." not in import_path:
raise TypeError("must be absolute import path string, not %r" % raise TypeError("must be absolute import path string, not %r" %
(import_path,)) (import_path,))
rest = [] module, attr = import_path.rsplit('.', 1)
target = import_path target = resolve(module)
target_parts = set(target.split(".")) if raising:
while target: annotated_getattr(target, attr, ann=module)
try: return attr, target
obj = __import__(target, None, None, "__doc__")
except ImportError as ex:
if hasattr(ex, 'name'):
# Python >= 3.3
failed_name = ex.name
else:
match = RE_IMPORT_ERROR_NAME.match(ex.args[0])
assert match
failed_name = match.group(1)
if "." not in target:
__tracebackhide__ = True
pytest.fail("could not import any sub part: %s" %
import_path)
elif failed_name != target \
and not any(p == failed_name for p in target_parts):
# target is importable but causes ImportError itself
__tracebackhide__ = True
pytest.fail("import error in %s: %s" % (target, ex.args[0]))
target, name = target.rsplit(".", 1)
rest.append(name)
else:
assert rest
try:
while len(rest) > 1:
attr = rest.pop()
obj = getattr(obj, attr)
attr = rest[0]
if raising:
getattr(obj, attr)
except AttributeError:
__tracebackhide__ = True
pytest.fail("object %r has no attribute %r" % (obj, attr))
return attr, obj
class Notset: class Notset:
def __repr__(self): def __repr__(self):
return "<notset>" return "<notset>"
notset = Notset() notset = Notset()
class monkeypatch: class monkeypatch:
""" Object keeping a record of setattr/item/env/syspath changes. """ """ Object keeping a record of setattr/item/env/syspath changes. """
def __init__(self): def __init__(self):
self._setattr = [] self._setattr = []
self._setitem = [] self._setitem = []
@ -114,14 +122,14 @@ class monkeypatch:
if value is notset: if value is notset:
if not isinstance(target, _basestring): if not isinstance(target, _basestring):
raise TypeError("use setattr(target, name, value) or " raise TypeError("use setattr(target, name, value) or "
"setattr(target, value) with target being a dotted " "setattr(target, value) with target being a dotted "
"import string") "import string")
value = name value = name
name, target = derive_importpath(target, raising) name, target = derive_importpath(target, raising)
oldval = getattr(target, name, notset) oldval = getattr(target, name, notset)
if raising and oldval is notset: if raising and oldval is notset:
raise AttributeError("%r has no attribute %r" %(target, name)) raise AttributeError("%r has no attribute %r" % (target, name))
# avoid class descriptors like staticmethod/classmethod # avoid class descriptors like staticmethod/classmethod
if inspect.isclass(target): if inspect.isclass(target):
@ -233,7 +241,7 @@ class monkeypatch:
try: try:
del dictionary[name] del dictionary[name]
except KeyError: except KeyError:
pass # was already deleted, so we have the desired state pass # was already deleted, so we have the desired state
else: else:
dictionary[name] = value dictionary[name] = value
self._setitem[:] = [] self._setitem[:] = []

View File

@ -0,0 +1,31 @@
pytest-2.8.7
============
This is a hotfix release to solve a regression
in the builtin monkeypatch plugin that got introduced in 2.8.6.
pytest is a mature Python testing tool with more than a 1100 tests
against itself, passing on many different interpreters and platforms.
This release is supposed to be drop-in compatible to 2.8.5.
See below for the changes and see docs at:
http://pytest.org
As usual, you can upgrade from pypi via::
pip install -U pytest
Thanks to all who contributed to this release, among them:
Ronny Pfannschmidt
Happy testing,
The py.test Development Team
2.8.7 (compared to 2.8.6)
-------------------------
- fix #1338: use predictable object resolution for monkeypatch

View File

@ -26,7 +26,7 @@ you will see the return value of the function call::
$ py.test test_assert1.py $ py.test test_assert1.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -143,7 +143,7 @@ if you run this module::
$ py.test test_assert2.py $ py.test test_assert2.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -80,7 +80,7 @@ If you then run it with ``--lf``::
$ py.test --lf $ py.test --lf
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
run-last-failure: rerun last 2 failures run-last-failure: rerun last 2 failures
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items collected 50 items
@ -121,7 +121,7 @@ of ``FF`` and dots)::
$ py.test --ff $ py.test --ff
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
run-last-failure: rerun last 2 failures first run-last-failure: rerun last 2 failures first
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 50 items collected 50 items
@ -226,7 +226,7 @@ You can always peek at the content of the cache using the
$ py.test --cache-clear $ py.test --cache-clear
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -64,7 +64,7 @@ of the failing function and hide the other one::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items

View File

@ -49,7 +49,7 @@ then you can just invoke ``py.test`` without command line options::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 1 items collected 1 items

View File

@ -31,7 +31,7 @@ You can then restrict a test run to only run tests marked with ``webtest``::
$ py.test -v -m webtest $ py.test -v -m webtest
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -45,7 +45,7 @@ Or the inverse, running all tests except the webtest ones::
$ py.test -v -m "not webtest" $ py.test -v -m "not webtest"
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -66,7 +66,7 @@ tests based on their module, class, method, or function name::
$ py.test -v test_server.py::TestClass::test_method $ py.test -v test_server.py::TestClass::test_method
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 5 items collecting ... collected 5 items
@ -79,7 +79,7 @@ You can also select on the class::
$ py.test -v test_server.py::TestClass $ py.test -v test_server.py::TestClass
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -92,7 +92,7 @@ Or select multiple nodes::
$ py.test -v test_server.py::TestClass test_server.py::test_send_http $ py.test -v test_server.py::TestClass test_server.py::test_send_http
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items collecting ... collected 8 items
@ -130,7 +130,7 @@ select tests based on their names::
$ py.test -v -k http # running with the above defined example module $ py.test -v -k http # running with the above defined example module
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -144,7 +144,7 @@ And you can also run all tests except the ones that match the keyword::
$ py.test -k "not send_http" -v $ py.test -k "not send_http" -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -160,7 +160,7 @@ Or to select "http" and "quick" tests::
$ py.test -k "http or quick" -v $ py.test -k "http or quick" -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 4 items collecting ... collected 4 items
@ -350,7 +350,7 @@ the test needs::
$ py.test -E stage2 $ py.test -E stage2
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -362,7 +362,7 @@ and here is one that specifies exactly the environment needed::
$ py.test -E stage1 $ py.test -E stage1
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -481,7 +481,7 @@ then you will see two test skipped and two executed tests as expected::
$ py.test -rs # this option reports skip reasons $ py.test -rs # this option reports skip reasons
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -495,7 +495,7 @@ Note that if you specify a platform via the marker-command line option like this
$ py.test -m linux2 $ py.test -m linux2
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -547,7 +547,7 @@ We can now use the ``-m option`` to select one set::
$ py.test -m interface --tb=short $ py.test -m interface --tb=short
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -569,7 +569,7 @@ or to select both "event" and "interface" tests::
$ py.test -m "interface or event" --tb=short $ py.test -m "interface or event" --tb=short
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items

View File

@ -27,7 +27,7 @@ now execute the test specification::
nonpython $ py.test test_simple.yml nonpython $ py.test test_simple.yml
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items collected 2 items
@ -59,7 +59,7 @@ consulted when reporting in ``verbose`` mode::
nonpython $ py.test -v nonpython $ py.test -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collecting ... collected 2 items collecting ... collected 2 items
@ -81,7 +81,7 @@ interesting to just look at the collection tree::
nonpython $ py.test --collect-only nonpython $ py.test --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR/nonpython, inifile: rootdir: $REGENDOC_TMPDIR/nonpython, inifile:
collected 2 items collected 2 items
<YamlFile 'test_simple.yml'> <YamlFile 'test_simple.yml'>

View File

@ -130,7 +130,7 @@ objects, they are still using the default pytest representation::
$ py.test test_time.py --collect-only $ py.test test_time.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 6 items collected 6 items
<Module 'test_time.py'> <Module 'test_time.py'>
@ -181,7 +181,7 @@ this is a fully self-contained example which you can run with::
$ py.test test_scenarios.py $ py.test test_scenarios.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
@ -194,7 +194,7 @@ If you just collect tests you'll also nicely see 'advanced' and 'basic' as varia
$ py.test --collect-only test_scenarios.py $ py.test --collect-only test_scenarios.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
<Module 'test_scenarios.py'> <Module 'test_scenarios.py'>
@ -259,7 +259,7 @@ Let's first see how it looks like at collection time::
$ py.test test_backends.py --collect-only $ py.test test_backends.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
<Module 'test_backends.py'> <Module 'test_backends.py'>
@ -320,7 +320,7 @@ The result of this test will be successful::
$ py.test test_indirect_list.py --collect-only $ py.test test_indirect_list.py --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
<Module 'test_indirect_list.py'> <Module 'test_indirect_list.py'>
@ -369,7 +369,7 @@ argument sets to use for each test function. Let's run it::
$ py.test -q $ py.test -q
F.. F..
======= FAILURES ======== ======= FAILURES ========
_______ TestClass.test_equals[2-1] ________ _______ TestClass.test_equals[1-2] ________
self = <test_parametrize.TestClass object at 0xdeadbeef>, a = 1, b = 2 self = <test_parametrize.TestClass object at 0xdeadbeef>, a = 1, b = 2
@ -397,11 +397,8 @@ is to be run with different sets of arguments for its three arguments:
Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize):: Running it results in some skips if we don't have all the python interpreters installed and otherwise runs all combinations (5 interpreters times 5 interpreters times 3 objects to serialize/deserialize)::
. $ py.test -rs -q multipython.py . $ py.test -rs -q multipython.py
ssssssssssss...ssssssssssss ...........................
======= short test summary info ======== 27 passed in 0.12 seconds
SKIP [12] $REGENDOC_TMPDIR/CWD/multipython.py:22: 'python2.6' not found
SKIP [12] $REGENDOC_TMPDIR/CWD/multipython.py:22: 'python3.3' not found
3 passed, 24 skipped in 0.12 seconds
Indirect parametrization of optional implementations/imports Indirect parametrization of optional implementations/imports
-------------------------------------------------------------------- --------------------------------------------------------------------
@ -448,7 +445,7 @@ If you run this with reporting for skips enabled::
$ py.test -rs test_module.py $ py.test -rs test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items

View File

@ -82,7 +82,7 @@ then the test collection looks like this::
$ py.test --collect-only $ py.test --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: setup.cfg rootdir: $REGENDOC_TMPDIR, inifile: setup.cfg
collected 2 items collected 2 items
<Module 'check_myapp.py'> <Module 'check_myapp.py'>
@ -128,7 +128,7 @@ You can always peek at the collection tree without running tests like this::
. $ py.test --collect-only pythoncollection.py . $ py.test --collect-only pythoncollection.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 3 items collected 3 items
<Module 'CWD/pythoncollection.py'> <Module 'CWD/pythoncollection.py'>
@ -182,7 +182,7 @@ interpreters and will leave out the setup.py file::
$ py.test --collect-only $ py.test --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini rootdir: $REGENDOC_TMPDIR, inifile: pytest.ini
collected 0 items collected 0 items

View File

@ -13,7 +13,7 @@ get on the terminal - we are working on that):
assertion $ py.test failure_demo.py assertion $ py.test failure_demo.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR/assertion, inifile: rootdir: $REGENDOC_TMPDIR/assertion, inifile:
collected 42 items collected 42 items

View File

@ -108,7 +108,7 @@ directory with the above conftest.py::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -156,7 +156,7 @@ and when running it will see a skipped "slow" test::
$ py.test -rs # "-rs" means report details on the little 's' $ py.test -rs # "-rs" means report details on the little 's'
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -170,7 +170,7 @@ Or run it including the ``slow`` marked test::
$ py.test --runslow $ py.test --runslow
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -262,7 +262,7 @@ which will add the string to the test header accordingly::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
project deps: mylib-1.1 project deps: mylib-1.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -286,7 +286,7 @@ which will add info only when run with "--v"::
$ py.test -v $ py.test -v
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
info1: did you know that ... info1: did you know that ...
did you? did you?
@ -299,7 +299,7 @@ and nothing when run plainly::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 0 items collected 0 items
@ -332,7 +332,7 @@ Now we can profile which test functions execute the slowest::
$ py.test --durations=3 $ py.test --durations=3
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items
@ -394,11 +394,14 @@ If we run this::
$ py.test -rx $ py.test -rx
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 4 items collected 4 items
test_step.py .Fx. test_step.py .Fx.
======= short test summary info ========
XFAIL test_step.py::TestUserHandling::()::test_deletion
reason: previous test failed (test_modification)
======= FAILURES ======== ======= FAILURES ========
_______ TestUserHandling.test_modification ________ _______ TestUserHandling.test_modification ________
@ -410,9 +413,6 @@ If we run this::
E assert 0 E assert 0
test_step.py:9: AssertionError test_step.py:9: AssertionError
======= short test summary info ========
XFAIL test_step.py::TestUserHandling::()::test_deletion
reason: previous test failed (test_modification)
======= 1 failed, 2 passed, 1 xfailed in 0.12 seconds ======== ======= 1 failed, 2 passed, 1 xfailed in 0.12 seconds ========
We'll see that ``test_deletion`` was not executed because ``test_modification`` We'll see that ``test_deletion`` was not executed because ``test_modification``
@ -465,7 +465,7 @@ We can run this::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 7 items collected 7 items
@ -479,7 +479,7 @@ We can run this::
file $REGENDOC_TMPDIR/b/test_error.py, line 1 file $REGENDOC_TMPDIR/b/test_error.py, line 1
def test_root(db): # no db here, will error out def test_root(db): # no db here, will error out
fixture 'db' not found fixture 'db' not found
available fixtures: capsys, capfd, pytestconfig, tmpdir_factory, monkeypatch, record_xml_property, cache, tmpdir, recwarn available fixtures: record_xml_property, pytestconfig, cache, capsys, recwarn, monkeypatch, tmpdir, capfd, tmpdir_factory
use 'py.test --fixtures [testpath]' for help on them. use 'py.test --fixtures [testpath]' for help on them.
$REGENDOC_TMPDIR/b/test_error.py:1 $REGENDOC_TMPDIR/b/test_error.py:1
@ -569,7 +569,7 @@ and run them::
$ py.test test_module.py $ py.test test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -660,7 +660,7 @@ and run it::
$ py.test -s test_module.py $ py.test -s test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items

View File

@ -75,7 +75,7 @@ marked ``smtp`` fixture function. Running the test looks like this::
$ py.test test_smtpsimple.py $ py.test test_smtpsimple.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items
@ -193,7 +193,7 @@ inspect what is going on and can now run the tests::
$ py.test test_module.py $ py.test test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items
@ -480,7 +480,7 @@ Running the above tests results in the following test IDs being used::
$ py.test --collect-only $ py.test --collect-only
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 10 items collected 10 items
<Module 'test_anothersmtp.py'> <Module 'test_anothersmtp.py'>
@ -531,7 +531,7 @@ Here we declare an ``app`` fixture which receives the previously defined
$ py.test -v test_appsetup.py $ py.test -v test_appsetup.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 2 items collecting ... collected 2 items
@ -597,7 +597,7 @@ Let's run the tests in verbose mode and with looking at the print-output::
$ py.test -v -s test_module.py $ py.test -v -s test_module.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1 -- $PYTHON_PREFIX/bin/python3.4
cachedir: .cache cachedir: .cache
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collecting ... collected 8 items collecting ... collected 8 items

View File

@ -27,7 +27,7 @@ Installation options::
To check your installation has installed the correct version:: To check your installation has installed the correct version::
$ py.test --version $ py.test --version
This is pytest version 2.8.5, imported from $PYTHON_PREFIX/lib/python3.4/site-packages/pytest.py This is pytest version 2.8.7, imported from $PYTHON_PREFIX/lib/python3.4/site-packages/pytest.py
If you get an error checkout :ref:`installation issues`. If you get an error checkout :ref:`installation issues`.
@ -49,7 +49,7 @@ That's it. You can execute the test function now::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -55,7 +55,7 @@ them in turn::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items
@ -103,7 +103,7 @@ Let's run this::
$ py.test $ py.test
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 3 items collected 3 items

View File

@ -160,7 +160,7 @@ Running it with the report-on-xfail option gives this output::
example $ py.test -rx xfail_demo.py example $ py.test -rx xfail_demo.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR/example, inifile: rootdir: $REGENDOC_TMPDIR/example, inifile:
collected 7 items collected 7 items

View File

@ -29,7 +29,7 @@ Running this would result in a passed test except for the last
$ py.test test_tmpdir.py $ py.test test_tmpdir.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 1 items collected 1 items

View File

@ -88,7 +88,7 @@ the ``self.db`` values in the traceback::
$ py.test test_unittest_db.py $ py.test test_unittest_db.py
======= test session starts ======== ======= test session starts ========
platform linux -- Python 3.4.3, pytest-2.8.5, py-1.4.31, pluggy-0.3.1 platform linux -- Python 3.4.3, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: $REGENDOC_TMPDIR, inifile: rootdir: $REGENDOC_TMPDIR, inifile:
collected 2 items collected 2 items

View File

@ -1,9 +1,11 @@
import os, sys import os
import sys
import textwrap import textwrap
import pytest import pytest
from _pytest.monkeypatch import monkeypatch as MonkeyPatch from _pytest.monkeypatch import monkeypatch as MonkeyPatch
def pytest_funcarg__mp(request): def pytest_funcarg__mp(request):
cwd = os.getcwd() cwd = os.getcwd()
sys_path = list(sys.path) sys_path = list(sys.path)
@ -15,9 +17,11 @@ def pytest_funcarg__mp(request):
request.addfinalizer(cleanup) request.addfinalizer(cleanup)
return MonkeyPatch() return MonkeyPatch()
def test_setattr(): def test_setattr():
class A: class A:
x = 1 x = 1
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
pytest.raises(AttributeError, "monkeypatch.setattr(A, 'notexists', 2)") pytest.raises(AttributeError, "monkeypatch.setattr(A, 'notexists', 2)")
monkeypatch.setattr(A, 'y', 2, raising=False) monkeypatch.setattr(A, 'y', 2, raising=False)
@ -34,9 +38,10 @@ def test_setattr():
assert A.x == 1 assert A.x == 1
A.x = 5 A.x = 5
monkeypatch.undo() # double-undo makes no modification monkeypatch.undo() # double-undo makes no modification
assert A.x == 5 assert A.x == 5
class TestSetattrWithImportPath: class TestSetattrWithImportPath:
def test_string_expression(self, monkeypatch): def test_string_expression(self, monkeypatch):
monkeypatch.setattr("os.path.abspath", lambda x: "hello2") monkeypatch.setattr("os.path.abspath", lambda x: "hello2")
@ -57,11 +62,11 @@ class TestSetattrWithImportPath:
pytest.raises(TypeError, lambda: monkeypatch.setattr(None, None)) pytest.raises(TypeError, lambda: monkeypatch.setattr(None, None))
def test_unknown_import(self, monkeypatch): def test_unknown_import(self, monkeypatch):
pytest.raises(pytest.fail.Exception, pytest.raises(ImportError,
lambda: monkeypatch.setattr("unkn123.classx", None)) lambda: monkeypatch.setattr("unkn123.classx", None))
def test_unknown_attr(self, monkeypatch): def test_unknown_attr(self, monkeypatch):
pytest.raises(pytest.fail.Exception, pytest.raises(AttributeError,
lambda: monkeypatch.setattr("os.path.qweqwe", None)) lambda: monkeypatch.setattr("os.path.qweqwe", None))
def test_unknown_attr_non_raising(self, monkeypatch): def test_unknown_attr_non_raising(self, monkeypatch):
@ -75,9 +80,11 @@ class TestSetattrWithImportPath:
monkeypatch.undo() monkeypatch.undo()
assert os.path.abspath assert os.path.abspath
def test_delattr(): def test_delattr():
class A: class A:
x = 1 x = 1
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
monkeypatch.delattr(A, 'x') monkeypatch.delattr(A, 'x')
assert not hasattr(A, 'x') assert not hasattr(A, 'x')
@ -93,6 +100,7 @@ def test_delattr():
monkeypatch.undo() monkeypatch.undo()
assert A.x == 1 assert A.x == 1
def test_setitem(): def test_setitem():
d = {'x': 1} d = {'x': 1}
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -110,6 +118,7 @@ def test_setitem():
monkeypatch.undo() monkeypatch.undo()
assert d['x'] == 5 assert d['x'] == 5
def test_setitem_deleted_meanwhile(): def test_setitem_deleted_meanwhile():
d = {} d = {}
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -118,6 +127,7 @@ def test_setitem_deleted_meanwhile():
monkeypatch.undo() monkeypatch.undo()
assert not d assert not d
@pytest.mark.parametrize("before", [True, False]) @pytest.mark.parametrize("before", [True, False])
def test_setenv_deleted_meanwhile(before): def test_setenv_deleted_meanwhile(before):
key = "qwpeoip123" key = "qwpeoip123"
@ -133,6 +143,7 @@ def test_setenv_deleted_meanwhile(before):
else: else:
assert key not in os.environ assert key not in os.environ
def test_delitem(): def test_delitem():
d = {'x': 1} d = {'x': 1}
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -149,6 +160,7 @@ def test_delitem():
monkeypatch.undo() monkeypatch.undo()
assert d == {'hello': 'world', 'x': 1} assert d == {'hello': 'world', 'x': 1}
def test_setenv(): def test_setenv():
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
monkeypatch.setenv('XYZ123', 2) monkeypatch.setenv('XYZ123', 2)
@ -157,6 +169,7 @@ def test_setenv():
monkeypatch.undo() monkeypatch.undo()
assert 'XYZ123' not in os.environ assert 'XYZ123' not in os.environ
def test_delenv(): def test_delenv():
name = 'xyz1234' name = 'xyz1234'
assert name not in os.environ assert name not in os.environ
@ -177,6 +190,7 @@ def test_delenv():
if name in os.environ: if name in os.environ:
del os.environ[name] del os.environ[name]
def test_setenv_prepend(): def test_setenv_prepend():
import os import os
monkeypatch = MonkeyPatch() monkeypatch = MonkeyPatch()
@ -187,6 +201,7 @@ def test_setenv_prepend():
monkeypatch.undo() monkeypatch.undo()
assert 'XYZ123' not in os.environ assert 'XYZ123' not in os.environ
def test_monkeypatch_plugin(testdir): def test_monkeypatch_plugin(testdir):
reprec = testdir.inline_runsource(""" reprec = testdir.inline_runsource("""
def test_method(monkeypatch): def test_method(monkeypatch):
@ -195,6 +210,7 @@ def test_monkeypatch_plugin(testdir):
res = reprec.countoutcomes() res = reprec.countoutcomes()
assert tuple(res) == (1, 0, 0), res assert tuple(res) == (1, 0, 0), res
def test_syspath_prepend(mp): def test_syspath_prepend(mp):
old = list(sys.path) old = list(sys.path)
mp.syspath_prepend('world') mp.syspath_prepend('world')
@ -206,6 +222,7 @@ def test_syspath_prepend(mp):
mp.undo() mp.undo()
assert sys.path == old assert sys.path == old
def test_syspath_prepend_double_undo(mp): def test_syspath_prepend_double_undo(mp):
mp.syspath_prepend('hello world') mp.syspath_prepend('hello world')
mp.undo() mp.undo()
@ -213,20 +230,24 @@ def test_syspath_prepend_double_undo(mp):
mp.undo() mp.undo()
assert sys.path[-1] == 'more hello world' assert sys.path[-1] == 'more hello world'
def test_chdir_with_path_local(mp, tmpdir): def test_chdir_with_path_local(mp, tmpdir):
mp.chdir(tmpdir) mp.chdir(tmpdir)
assert os.getcwd() == tmpdir.strpath assert os.getcwd() == tmpdir.strpath
def test_chdir_with_str(mp, tmpdir): def test_chdir_with_str(mp, tmpdir):
mp.chdir(tmpdir.strpath) mp.chdir(tmpdir.strpath)
assert os.getcwd() == tmpdir.strpath assert os.getcwd() == tmpdir.strpath
def test_chdir_undo(mp, tmpdir): def test_chdir_undo(mp, tmpdir):
cwd = os.getcwd() cwd = os.getcwd()
mp.chdir(tmpdir) mp.chdir(tmpdir)
mp.undo() mp.undo()
assert os.getcwd() == cwd assert os.getcwd() == cwd
def test_chdir_double_undo(mp, tmpdir): def test_chdir_double_undo(mp, tmpdir):
mp.chdir(tmpdir.strpath) mp.chdir(tmpdir.strpath)
mp.undo() mp.undo()
@ -234,6 +255,7 @@ def test_chdir_double_undo(mp, tmpdir):
mp.undo() mp.undo()
assert os.getcwd() == tmpdir.strpath assert os.getcwd() == tmpdir.strpath
def test_issue185_time_breaks(testdir): def test_issue185_time_breaks(testdir):
testdir.makepyfile(""" testdir.makepyfile("""
import time import time
@ -247,6 +269,7 @@ def test_issue185_time_breaks(testdir):
*1 passed* *1 passed*
""") """)
def test_importerror(testdir): def test_importerror(testdir):
p = testdir.mkpydir("package") p = testdir.mkpydir("package")
p.join("a.py").write(textwrap.dedent("""\ p.join("a.py").write(textwrap.dedent("""\
@ -260,7 +283,7 @@ def test_importerror(testdir):
""")) """))
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(""" result.stdout.fnmatch_lines("""
*import error in package.a.x: No module named {0}doesnotexist{0}* *import error in package.a: No module named {0}doesnotexist{0}*
""".format("'" if sys.version_info > (3, 0) else "")) """.format("'" if sys.version_info > (3, 0) else ""))
@ -275,11 +298,12 @@ class SampleNewInherit(SampleNew):
class SampleOld: class SampleOld:
#oldstyle on python2 # oldstyle on python2
@staticmethod @staticmethod
def hello(): def hello():
return True return True
class SampleOldInherit(SampleOld): class SampleOldInherit(SampleOld):
pass pass
@ -297,4 +321,10 @@ def test_issue156_undo_staticmethod(Sample):
monkeypatch.undo() monkeypatch.undo()
assert Sample.hello() assert Sample.hello()
def test_issue1338_name_resolving():
pytest.importorskip('requests')
monkeypatch = MonkeyPatch()
try:
monkeypatch.delattr('requests.sessions.Session.request')
finally:
monkeypatch.undo()

View File

@ -12,6 +12,7 @@ passenv = USER USERNAME
deps= deps=
nose nose
mock mock
requests
[testenv:py26] [testenv:py26]
commands= py.test --lsof -rfsxX {posargs:testing} commands= py.test --lsof -rfsxX {posargs:testing}