[Python-porting] Control of hash randomization

Chris Jerdonek chris.jerdonek at gmail.com
Sun May 27 16:11:22 CEST 2012


On Sun, May 27, 2012 at 1:07 AM, Aaron Meurer <asmeurer at gmail.com> wrote:
> On Sun, May 27, 2012 at 12:22 AM,  <martin at v.loewis.de> wrote:
>> Also: if a test fails due to hash randomization, it should normally
>> be possible to find the root cause by just reviewing the code (long
>> enough). It may not be possible to reproduce the failure, but it
>> should be obvious if a certain piece of code would fail under hash
>> randomization.
>>
> Ha!  Well, that's easy enough to say, but if all you have to work with
> is an assertion that failed, and a very large code base, it might not
> be so straight forward.  Furthermore, such situations are very often
> not obvious (or else the author probably would not have written them
> in the first place).

Sorry if this is obvious, but another suggestion is to include more
information in the assertion error message.  It's not clear from the
discussion so far if this is being done.  That way you can learn more
about the state of the code during the assertion failure.

I also spot checked a few spots in SymPy and see this being done frequently--

    def test_ratint():
        assert ratint(S(0), x) == 0

Options include using the extended form of the assert statement, or
the msg parameter of unittest's various assertion methods.

--Chris


More information about the Python-porting mailing list