Fix existing tests now that we are using standard warnings
This commit is contained in:
@@ -383,44 +383,7 @@ class TestMetafunc(object):
|
||||
)
|
||||
assert result == ["a-a0", "a-a1", "a-a2"]
|
||||
|
||||
@pytest.mark.issue351
|
||||
def test_idmaker_idfn_exception(self):
|
||||
from _pytest.python import idmaker
|
||||
from _pytest.recwarn import WarningsRecorder
|
||||
|
||||
class BadIdsException(Exception):
|
||||
pass
|
||||
|
||||
def ids(val):
|
||||
raise BadIdsException("ids raised")
|
||||
|
||||
rec = WarningsRecorder()
|
||||
with rec:
|
||||
idmaker(
|
||||
("a", "b"),
|
||||
[
|
||||
pytest.param(10.0, IndexError()),
|
||||
pytest.param(20, KeyError()),
|
||||
pytest.param("three", [1, 2, 3]),
|
||||
],
|
||||
idfn=ids,
|
||||
)
|
||||
|
||||
assert [str(i.message) for i in rec.list] == [
|
||||
"Raised while trying to determine id of parameter a at position 0."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
"Raised while trying to determine id of parameter b at position 0."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
"Raised while trying to determine id of parameter a at position 1."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
"Raised while trying to determine id of parameter b at position 1."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
"Raised while trying to determine id of parameter a at position 2."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
"Raised while trying to determine id of parameter b at position 2."
|
||||
"\nUpdate your code as this will raise an error in pytest-4.0.",
|
||||
]
|
||||
|
||||
@pytest.mark.filterwarnings("default")
|
||||
def test_parametrize_ids_exception(self, testdir):
|
||||
"""
|
||||
:param testdir: the instance of Testdir class, a temporary
|
||||
@@ -438,13 +401,14 @@ class TestMetafunc(object):
|
||||
pass
|
||||
"""
|
||||
)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
result = testdir.runpytest("--collect-only")
|
||||
result = testdir.runpytest("--collect-only")
|
||||
result.stdout.fnmatch_lines(
|
||||
[
|
||||
"<Module 'test_parametrize_ids_exception.py'>",
|
||||
" <Function 'test_foo[a]'>",
|
||||
" <Function 'test_foo[b]'>",
|
||||
"*test_parametrize_ids_exception.py:5: *parameter arg at position 0*",
|
||||
"*test_parametrize_ids_exception.py:5: *parameter arg at position 1*",
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from _pytest.python import PyCollector
|
||||
|
||||
|
||||
class PyCollectorMock(PyCollector):
|
||||
"""evil hack"""
|
||||
|
||||
def __init__(self):
|
||||
self.called = False
|
||||
|
||||
def _makeitem(self, *k):
|
||||
"""hack to disable the actual behaviour"""
|
||||
self.called = True
|
||||
|
||||
|
||||
def test_pycollector_makeitem_is_deprecated():
|
||||
|
||||
collector = PyCollectorMock()
|
||||
with pytest.deprecated_call():
|
||||
collector.makeitem("foo", "bar")
|
||||
assert collector.called
|
||||
Reference in New Issue
Block a user