Skip to content

Commit

Permalink
Future-proof test runner
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentRDC committed Dec 2, 2020
1 parent 2a548d8 commit ffa65c8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
3 changes: 2 additions & 1 deletion tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,4 +467,5 @@ def tearDown(self):


if __name__ == "__main__":
unittest.main()
from utils import FutureProofTestRunner
unittest.main(testRunner=FutureProofTestRunner)
10 changes: 8 additions & 2 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import unittest
from pathlib import Path
from tempfile import gettempdir
from contextlib import redirect_stdout
import io


from iris import AbstractRawDataset, DiffractionDataset
from iris.plugins import load_plugin
Expand Down Expand Up @@ -45,8 +48,11 @@ def test_reduction(self):
class TestBrokenPlugin(unittest.TestCase):
def test_loading_broken_plugin(self):
""" Test that exceptions are caught when loading a broken plug-in. """
load_plugin(BROKEN_PLUGIN_PATH)
to_the_void = io.StringIO()
with redirect_stdout(to_the_void):
load_plugin(BROKEN_PLUGIN_PATH)


if __name__ == "__main__":
unittest.main()
from utils import FutureProofTestRunner
unittest.main(testRunner=FutureProofTestRunner)
3 changes: 2 additions & 1 deletion tests/test_raw.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ def test_init_metadata(self):


if __name__ == "__main__":
unittest.main()
from utils import FutureProofTestRunner
unittest.main(testRunner=FutureProofTestRunner)
13 changes: 13 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"""
Utility functions for tests
"""
import unittest
import warnings

class FutureProofTestRunner(unittest.TextTestRunner):
"""
A test runner that raises errors on Deprecation warnings.
"""
def run(self, *args, **kwargs):
warnings.filterwarnings("error", category=DeprecationWarning)
return super().run(*args, **kwargs)

0 comments on commit ffa65c8

Please sign in to comment.