Merge remote-tracking branch 'upstream/features' into features
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from _pytest.outcomes import Failed
|
||||
import pytest
|
||||
import sys
|
||||
|
||||
@@ -61,6 +62,11 @@ class TestRaises(object):
|
||||
with pytest.raises(TypeError):
|
||||
pytest.raises('wrong', lambda: None)
|
||||
|
||||
def test_invalid_arguments_to_raises(self):
|
||||
with pytest.raises(TypeError, match='unknown'):
|
||||
with pytest.raises(TypeError, unknown='bogus'):
|
||||
raise ValueError()
|
||||
|
||||
def test_tuple(self):
|
||||
with pytest.raises((KeyError, ValueError)):
|
||||
raise KeyError('oops')
|
||||
@@ -142,3 +148,20 @@ class TestRaises(object):
|
||||
with pytest.raises(ValueError):
|
||||
with pytest.raises(IndexError, match='nomatch'):
|
||||
int('asdf')
|
||||
|
||||
def test_raises_exception_looks_iterable(self):
|
||||
from six import add_metaclass
|
||||
|
||||
class Meta(type(object)):
|
||||
def __getitem__(self, item):
|
||||
return 1/0
|
||||
|
||||
def __len__(self):
|
||||
return 1
|
||||
|
||||
@add_metaclass(Meta)
|
||||
class ClassLooksIterableException(Exception):
|
||||
pass
|
||||
|
||||
with pytest.raises(Failed, match="DID NOT RAISE <class 'raises.ClassLooksIterableException'>"):
|
||||
pytest.raises(ClassLooksIterableException, lambda: None)
|
||||
|
||||
@@ -839,22 +839,22 @@ class TestAssertionRewriteHookDetails(object):
|
||||
def test_write_pyc(self, testdir, tmpdir, monkeypatch):
|
||||
from _pytest.assertion.rewrite import _write_pyc
|
||||
from _pytest.assertion import AssertionState
|
||||
try:
|
||||
import __builtin__ as b
|
||||
except ImportError:
|
||||
import builtins as b
|
||||
import atomicwrites
|
||||
from contextlib import contextmanager
|
||||
config = testdir.parseconfig([])
|
||||
state = AssertionState(config, "rewrite")
|
||||
source_path = tmpdir.ensure("source.py")
|
||||
pycpath = tmpdir.join("pyc").strpath
|
||||
assert _write_pyc(state, [1], source_path.stat(), pycpath)
|
||||
|
||||
def open(*args):
|
||||
@contextmanager
|
||||
def atomic_write_failed(fn, mode='r', overwrite=False):
|
||||
e = IOError()
|
||||
e.errno = 10
|
||||
raise e
|
||||
yield # noqa
|
||||
|
||||
monkeypatch.setattr(b, "open", open)
|
||||
monkeypatch.setattr(atomicwrites, "atomic_write", atomic_write_failed)
|
||||
assert not _write_pyc(state, [1], source_path.stat(), pycpath)
|
||||
|
||||
def test_resources_provider_for_loader(self, testdir):
|
||||
|
||||
@@ -868,17 +868,13 @@ def test_record_property(testdir):
|
||||
def test_record(record_property, other):
|
||||
record_property("foo", "<1");
|
||||
""")
|
||||
result, dom = runandparse(testdir, '-rw')
|
||||
result, dom = runandparse(testdir, '-rwv')
|
||||
node = dom.find_first_by_tag("testsuite")
|
||||
tnode = node.find_first_by_tag("testcase")
|
||||
psnode = tnode.find_first_by_tag('properties')
|
||||
pnodes = psnode.find_by_tag('property')
|
||||
pnodes[0].assert_attr(name="bar", value="1")
|
||||
pnodes[1].assert_attr(name="foo", value="<1")
|
||||
result.stdout.fnmatch_lines([
|
||||
'test_record_property.py::test_record',
|
||||
'*record_property*experimental*',
|
||||
])
|
||||
|
||||
|
||||
def test_record_property_same_name(testdir):
|
||||
|
||||
@@ -113,7 +113,7 @@ class TestDeprecatedCall(object):
|
||||
pass
|
||||
|
||||
msg = 'Did not produce DeprecationWarning or PendingDeprecationWarning'
|
||||
with pytest.raises(AssertionError, matches=msg):
|
||||
with pytest.raises(AssertionError, match=msg):
|
||||
if mode == 'call':
|
||||
pytest.deprecated_call(f)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user