0

I was working on a customised error message when I came across an issue using: pytest.raises(error, match=f'error_message_part1 {set1 - set2} error_message_part2')

Basically, I don't understand how the ordering of the result between set1 and set2 works. There seems to be an ordering even though the documentation as far as I went through it says otherwise. I am working with python 3.9.10

I am interested in understanding how the 'sorting' of the result works.

Here is the simple example that highlighted the issue:

>>> a = {'a', 'b', 'c', 'd', 'e'}
>>> b = {'b', 'd'}
>>> a - b
{'e', 'a', 'c'}

>>> a = {'c', 'b', 'a', 'd', 'e'}
>>> a - b
{'e', 'a', 'c'}

>>> a = {'e', 'b', 'a', 'd', 'c'}
>>> a - b
{'e', 'a', 'c'}
jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
UmbrAA
  • 1
  • Sets are not _semantically_ ordered. That doesn't mean that they won't retain a particular order within a particular session. – jonrsharpe Mar 30 '22 at 14:15
  • Does this answer your question? [Why is the order in dictionaries and sets arbitrary?](https://stackoverflow.com/questions/15479928/why-is-the-order-in-dictionaries-and-sets-arbitrary) – jonrsharpe Mar 30 '22 at 14:16
  • @jonrsharpe well I think that is the answer thank you ! Working on an error message the only solution I see is to convert my set into an ordered list. – UmbrAA Mar 30 '22 at 14:23

0 Answers0