Commit e1adeceb authored by Brett Cannon's avatar Brett Cannon

Clean up warnings filter use in test_tempfile.

parent 241bd982
...@@ -8,9 +8,6 @@ import warnings ...@@ -8,9 +8,6 @@ import warnings
import unittest import unittest
from test import support from test import support
warnings.filterwarnings("ignore",
category=RuntimeWarning,
message="mktemp", module=__name__)
if hasattr(os, 'stat'): if hasattr(os, 'stat'):
import stat import stat
...@@ -39,6 +36,16 @@ class TC(unittest.TestCase): ...@@ -39,6 +36,16 @@ class TC(unittest.TestCase):
str_check = re.compile(r"[a-zA-Z0-9_-]{6}$") str_check = re.compile(r"[a-zA-Z0-9_-]{6}$")
def setUp(self):
self._warnings_manager = support.check_warnings()
self._warnings_manager.__enter__()
warnings.filterwarnings("ignore", category=RuntimeWarning,
message="mktemp", module=__name__)
def tearDown(self):
self._warnings_manager.__exit__(None, None, None)
def failOnException(self, what, ei=None): def failOnException(self, what, ei=None):
if ei is None: if ei is None:
ei = sys.exc_info() ei = sys.exc_info()
...@@ -98,6 +105,7 @@ class test__RandomNameSequence(TC): ...@@ -98,6 +105,7 @@ class test__RandomNameSequence(TC):
def setUp(self): def setUp(self):
self.r = tempfile._RandomNameSequence() self.r = tempfile._RandomNameSequence()
super().setUp()
def test_get_six_char_str(self): def test_get_six_char_str(self):
# _RandomNameSequence returns a six-character string # _RandomNameSequence returns a six-character string
...@@ -499,11 +507,13 @@ class test_mktemp(TC): ...@@ -499,11 +507,13 @@ class test_mktemp(TC):
# We must also suppress the RuntimeWarning it generates. # We must also suppress the RuntimeWarning it generates.
def setUp(self): def setUp(self):
self.dir = tempfile.mkdtemp() self.dir = tempfile.mkdtemp()
super().setUp()
def tearDown(self): def tearDown(self):
if self.dir: if self.dir:
os.rmdir(self.dir) os.rmdir(self.dir)
self.dir = None self.dir = None
super().tearDown()
class mktemped: class mktemped:
_unlink = os.unlink _unlink = os.unlink
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment