Skip to content

Commit 36c28ee

Browse files
add test case for invalid warning handeling
1 parent af3e975 commit 36c28ee

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

testing/acceptance_test.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,11 @@ def test_func():
401401
)
402402

403403
@pytest.mark.parametrize("n", ["-n0", "-n1"])
404-
@pytest.mark.parametrize("warn_type", ["pytest", "builtin"])
404+
@pytest.mark.parametrize("warn_type", ["pytest", "builtin", "invalid"])
405405
def test_warnings(self, testdir, n, warn_type):
406406
from pkg_resources import parse_version
407407

408+
print(n, warn_type)
408409
if parse_version(pytest.__version__) < parse_version("3.1"):
409410
pytest.skip("pytest warnings requires >= 3.1")
410411

@@ -413,12 +414,21 @@ def test_warnings(self, testdir, n, warn_type):
413414
elif warn_type == "pytest":
414415
warn_code = """request.config.warn('', 'this is a warning',
415416
fslocation=py.path.local())"""
417+
elif warn_type == "invalid":
418+
warn_code = "msg = UserWarning('this is a warning'); msg.args = (); warnings.warn(msg)"
416419
else:
417420
assert False
418421
testdir.makepyfile(
419422
"""
420423
import warnings, py, pytest
421424
425+
class BadWarning(Warning):
426+
def __init__(self, param):
427+
self.param = param
428+
super(BadWarning, self).__init__()
429+
def __str__(self):
430+
return self.param
431+
422432
@pytest.mark.filterwarnings('ignore:config.warn has been deprecated')
423433
def test_func(request):
424434
{warn_code}

0 commit comments

Comments
 (0)