[Python-checkins] r63191 - python/trunk/Lib/test/test_py3kwarn.py

Eric Smith eric at trueblade.com
Tue May 13 01:49:36 CEST 2008


benjamin.peterson wrote:
> Author: benjamin.peterson
> Date: Tue May 13 00:26:05 2008
> New Revision: 63191
> 
> Log:
> Make error messages more helpful
> 
> 
> Modified:
>    python/trunk/Lib/test/test_py3kwarn.py
> 
> Modified: python/trunk/Lib/test/test_py3kwarn.py
> ==============================================================================
> --- python/trunk/Lib/test/test_py3kwarn.py	(original)
> +++ python/trunk/Lib/test/test_py3kwarn.py	Tue May 13 00:26:05 2008
> @@ -157,10 +157,13 @@
>                  try:
>                      __import__(module_name, level=0)
>                  except DeprecationWarning as exc:
> -                    self.assert_(module_name in exc.args[0])
> +                    self.assert_(module_name in exc.args[0],
> +                                 "%s warning didn't contain module name"
> +                                 % module_name)
>                  except ImportError:
>                      if not optional:
> -                        raise
> +                        self.fail("Non-optional module %s raised an "
> +                                  "ImportError." % module_name)
>                  else:
>                      self.fail("DeprecationWarning not raised for %s" %
>                                  module_name)

It might not be a problem here because the callers are well known, but 
this is the classic problem with %-formatting.  You really should write 
'"%s" % (module_name,)', because as you have it written it's an error if 
module_name is a tuple.

Or better yet, use str.format()!

Eric.


More information about the Python-checkins mailing list