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

Monty Taylor mordred at inaugust.com
Fri Feb 8 18:29:39 UTC 2013


On 02/08/2013 12: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)

It does not support it as a context manager. (in the with block) Neither
does testtools, which I've got patches up for quantum to migrate to.
However, testtools does have an ExpectedException context manager that
does work with python2.6. So hang on just a sec and we should have
something for you.


> 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
> 



More information about the OpenStack-dev mailing list