Fail tests on Python warnings.

Fixes #982.
This commit is contained in:
Florian Bruhin 2015-10-01 21:34:00 +02:00
parent f552f433f8
commit 65891c6f0d
2 changed files with 18 additions and 0 deletions

View File

@ -27,6 +27,7 @@ import collections
import itertools
import logging
import textwrap
import warnings
import pytest
@ -309,3 +310,10 @@ def py_proc():
def func(code):
return (sys.executable, ['-c', textwrap.dedent(code.strip('\n'))])
return func
@pytest.yield_fixture(autouse=True)
def fail_tests_on_warnings():
warnings.simplefilter('error')
yield
warnings.resetwarnings()

View File

@ -20,6 +20,11 @@
"""Various meta-tests for conftest.py."""
import warnings
import pytest
def test_qapp_name(qapp):
"""Make sure the QApplication name is changed when we use qapp."""
assert qapp.applicationName() == 'qute_test'
@ -28,3 +33,8 @@ def test_qapp_name(qapp):
def test_no_qapp(request):
"""Make sure a test without qapp doesn't use qapp (via autouse)."""
assert 'qapp' not in request.fixturenames
def test_fail_on_warnings():
with pytest.raises(PendingDeprecationWarning):
warnings.warn('test', PendingDeprecationWarning)