Add test.test_support.guard_warnings_filter . This function returns a context

manager that protects warnings.filter from being modified once the context is
exited.
This commit is contained in:
Brett Cannon 2006-12-13 23:09:53 +00:00
parent c745df8519
commit 6d9520c4f0
6 changed files with 37 additions and 26 deletions

View file

@ -178,10 +178,9 @@ class WichmannHill_TestBasicOps(TestBasicOps):
def test_bigrand(self):
# Verify warnings are raised when randrange is too large for random()
oldfilters = warnings.filters[:]
warnings.filterwarnings("error", "Underlying random")
self.assertRaises(UserWarning, self.gen.randrange, 2**60)
warnings.filters[:] = oldfilters
with test_support.guard_warnings_filter():
warnings.filterwarnings("error", "Underlying random")
self.assertRaises(UserWarning, self.gen.randrange, 2**60)
class SystemRandom_TestBasicOps(TestBasicOps):
gen = random.SystemRandom()