From eeb9a6254d7e333f86faf63f0d4e4f74749efec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Thu, 16 Aug 2012 20:29:08 +0200 Subject: Disable new warnings in tests. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaƫl Barrois --- tests/test_using.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'tests/test_using.py') diff --git a/tests/test_using.py b/tests/test_using.py index 681daa9..7b8b3d6 100644 --- a/tests/test_using.py +++ b/tests/test_using.py @@ -21,9 +21,12 @@ """Tests using factory.""" -import factory +import functools import os import sys +import warnings + +import factory from .compat import unittest @@ -70,6 +73,15 @@ class TestModel(FakeModel): pass +def disable_warnings(fun): + @functools.wraps(fun) + def decorated(*args, **kwargs): + with warnings.catch_warnings(): + warnings.simplefilter('ignore') + return fun(*args, **kwargs) + return decorated + + class SimpleBuildTestCase(unittest.TestCase): """Tests the minimalist 'factory.build/create' functions.""" @@ -100,11 +112,13 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.three, 3) self.assertEqual(obj.four, None) + @disable_warnings def test_create(self): obj = factory.create(FakeModel, foo='bar') self.assertEqual(obj.id, 2) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_create_batch(self): objs = factory.create_batch(FakeModel, 4, foo='bar') @@ -135,6 +149,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_generate_create(self): obj = factory.generate(FakeModel, factory.CREATE_STRATEGY, foo='bar') self.assertEqual(obj.id, 2) @@ -155,6 +170,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_generate_batch_create(self): objs = factory.generate_batch(FakeModel, factory.CREATE_STRATEGY, 20, foo='bar') @@ -180,6 +196,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_simple_generate_create(self): obj = factory.simple_generate(FakeModel, True, foo='bar') self.assertEqual(obj.id, 2) @@ -195,6 +212,7 @@ class SimpleBuildTestCase(unittest.TestCase): self.assertEqual(obj.id, None) self.assertEqual(obj.foo, 'bar') + @disable_warnings def test_simple_generate_batch_create(self): objs = factory.simple_generate_batch(FakeModel, True, 20, foo='bar') @@ -623,6 +641,7 @@ class UsingFactoryTestCase(unittest.TestCase): self.assertEqual('three', obj.three) self.assertEqual('four', obj.four) + @disable_warnings def testSetCreationFunction(self): def creation_function(class_to_create, **kwargs): return "This doesn't even return an instance of {0}".format(class_to_create.__name__) -- cgit v1.2.3