Skip to content

Commit

Permalink
Explicit test for DeprecationWarning using logging. Try to fix appvey…
Browse files Browse the repository at this point in the history
…or for 3.5+ as suggested.
  • Loading branch information
jamadden committed Nov 10, 2017
1 parent 75e97bb commit 94cb222
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
3 changes: 2 additions & 1 deletion appveyor.yml
Expand Up @@ -15,8 +15,9 @@ environment:
install:
- "SET PATH=C:\\Python%PYTHON%;c:\\Python%PYTHON%\\scripts;%PATH%"
- echo "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64 > "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64\vcvars64.bat"
- pip install -U setuptools
# NB: pip install -e .[test] fails for obscure namespace package reasons
- pip install .[test]
- pip install -U .[test]

build: false

Expand Down
1 change: 0 additions & 1 deletion setup.py
Expand Up @@ -81,7 +81,6 @@ def run_tests(self):
_fd, filename = tempfile.mkstemp(prefix='temprunner', text=True)
with open(filename, 'w') as scriptfile:
scriptfile.write(script)
scriptfile.close()

import subprocess
process = subprocess.Popen([sys.executable, filename])
Expand Down
22 changes: 20 additions & 2 deletions src/zope/testrunner/tests/test_runner.py
Expand Up @@ -181,9 +181,9 @@ def test_FakeInputContinueGenerator_close(self):
f = runner.FakeInputContinueGenerator()
f.close()

@unittest.skipIf(sys.warnoptions, "Only done if no user override")
class TestWarnings(unittest.TestCase):

@unittest.skipIf(sys.warnoptions, "Only done if no user override")
def test_warning_filter_default(self):
# When we run tests, we run them with a 'default' simplefilter.
# Note that this test will fail if PYTHONWARNINGS is set,
Expand All @@ -203,4 +203,22 @@ def test_warning_filter_default(self):
# For some reason, catch_warnings doesn't fully reset things,
# and we wind up with some duplicate entries in new_filters
self.assertEqual(set(old_filters), set(new_filters))
warnings.warn("This should be visible by default", DeprecationWarning)


def test_warnings_are_shown(self):
import warnings
import logging
from zope.testing.loggingsupport import InstalledHandler

handler = InstalledHandler("py.warnings", level=logging.WARNING)
self.addCleanup(handler.uninstall)

logging.captureWarnings(True)
self.addCleanup(logging.captureWarnings, False)

msg = "This should be visible by default"
warnings.warn(msg, DeprecationWarning)

self.assertEqual(1, len(handler.records))
self.assertIn('DeprecationWarning', handler.records[0].getMessage())
self.assertIn(msg, handler.records[0].getMessage())

0 comments on commit 94cb222

Please sign in to comment.