[openstack-dev] Does python2.6 not support 'with assertRaises()'?

Dolph Mathews dolph.mathews at gmail.com
Fri Feb 8 18:28:23 UTC 2013


"Changed in version 2.7: Added the ability to use
assertRaises()<http://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises>
as
a context manager."

Source: http://docs.python.org/2/library/unittest.html


-Dolph


On Fri, Feb 8, 2013 at 12:25 PM, Paul Michali <pcm at cisco.com> wrote:

> Did some googling and it looks like 2.6 doesn't support assertRaises as a
> context manager.
>
>
> PCM (Paul Michali)
>
> On Feb 8, 2013, at 1:17 PM, Paul Michali wrote:
>
> I'm working on a bug and I had this code, which passes UT on my system
> running python2.7, but fails Jenkin's python2.6 run:
>
>      def test_missing_required_config(self):
>          args = ['--config-file',
>                  os.path.join(TEST_ETC_AREA, 'bad-quantum.conf.test')]
>          with self.assertRaises(cfg.RequiredOptError):
>              config.parse(args=args)
>
> First Jenkins failure (looks like python2.6) says:
>
> ft116.1: quantum.tests.unit.test_config.RequiredConfigTest.test_missing_required_configTraceback (most recent call last):
>   File "/usr/lib/python2.6/unittest.py", line 279, in run
>     testMethod()
>   File "/home/jenkins/workspace/gate-quantum-python26/quantum/tests/unit/test_config.py", line 59, in test_missing_required_config
>     with self.assertRaises(cfg.RequiredOptError):
> TypeError: failUnlessRaises() takes at least 3 arguments (2 given)
>
> Is there an issue with 2.6 supporting with clause and assertRaises, or is there a backward compatibility issue? I'm trying changing it to this...
>
>
>     def *test_missing_required_config*(*self*):
>         args = [*'--**config**-file'*,
>                 os.path.join(TEST_ETC_AREA, *'bad-quantum.conf.test'*)]
>         *self*.assertRaises(cfg.RequiredOptError, config.parse, args=args)
>
>
> PCM (Paul Michali)
>
>
>
> _______________________________________________
> OpenStack-dev mailing list
> OpenStack-dev at lists.openstack.org
> http://lists.openstack.org/cgi-bin/mailman/listinfo/openstack-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstack.org/pipermail/openstack-dev/attachments/20130208/da03a184/attachment.html>


More information about the OpenStack-dev mailing list