Dealing with dicts in doctest

Cameron Simpson cs at cskk.id.au
Thu Jul 5 19:31:50 EDT 2018


On 05Jul2018 17:57, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
>I have a function which returns a dict, and I want to use doctest to
>ensure the documentation is correct. So I write a bunch of doctests:
>
>def func(arg):
>    """blah blah blah
>
>    >>> func(1)
>    {'a': 1, 'b': 2, 'c': 3}
>    """
>
>which is correct, *except* that dict keys have arbitrary order in the
>versions of Python I'm using.
>
>I have three ways of dealing with this. Which do you prefer?

Option 4:

    >>> func(1) == {'a': 1, 'b': 2, 'c': 3}
    True

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list