Testing list sequence question

Thomas Passin list1 at tompassin.net
Sat Mar 4 12:49:45 EST 2023


On 3/4/2023 11:38 AM, Gabor Urban wrote:
>   Hi guys,
> 
> I have a strange problem that I do not understand. I am testing function
> which returns a dictionary. The code should ensure that the keys of the
> dictionary are generated in a given order.
> 
> I am testing the function with the standard unittest module and use the
> assertListEqual statement to verify the sequence. Sometimes this test
> fails, sometimes passes without any change neither in the code, nor in the
> testcase. I am using "list(myDict.keys())" to create the list of the keys
> of the dictionary.
> 
> I am running Python 3.3 on MS Windows. Any idea why is this?

List order would not be guaranteed.  Sort the list first.  Then your 
problem should clear up.



More information about the Python-list mailing list