summaryrefslogtreecommitdiffstats
path: root/Doc/library/doctest.rst
diff options
context:
space:
mode:
authorStéphane Wirtel <stephane@wirtel.be>2018-10-20 08:43:32 (GMT)
committerJulien Palard <julien@palard.fr>2018-10-20 08:43:32 (GMT)
commit0522fd81dc6e3482c2d4c8719f1f85ad5924eede (patch)
treeddb98e5b3feeaec446a51028a9807ee23c859588 /Doc/library/doctest.rst
parenta5259fb05d03f4871837c14fed704541a20896c0 (diff)
downloadcpython-0522fd81dc6e3482c2d4c8719f1f85ad5924eede.zip
cpython-0522fd81dc6e3482c2d4c8719f1f85ad5924eede.tar.gz
cpython-0522fd81dc6e3482c2d4c8719f1f85ad5924eede.tar.bz2
bpo-34839: Add a 'before 3.6' in the section 'warnings' of doctest (GH-9736)
Diffstat (limited to 'Doc/library/doctest.rst')
-rw-r--r--Doc/library/doctest.rst18
1 files changed, 11 insertions, 7 deletions
diff --git a/Doc/library/doctest.rst b/Doc/library/doctest.rst
index 587a0a0..bc5a404 100644
--- a/Doc/library/doctest.rst
+++ b/Doc/library/doctest.rst
@@ -759,23 +759,27 @@ Warnings
:mod:`doctest` is serious about requiring exact matches in expected output. If
even a single character doesn't match, the test fails. This will probably
surprise you a few times, as you learn exactly what Python does and doesn't
-guarantee about output. For example, when printing a dict, Python doesn't
-guarantee that the key-value pairs will be printed in any particular order, so a
-test like ::
+guarantee about output. For example, when printing a set, Python doesn't
+guarantee that the element is printed in any particular order, so a test like ::
>>> foo()
- {"Hermione": "hippogryph", "Harry": "broomstick"}
+ {"Hermione", "Harry"}
is vulnerable! One workaround is to do ::
- >>> foo() == {"Hermione": "hippogryph", "Harry": "broomstick"}
+ >>> foo() == {"Hermione", "Harry"}
True
instead. Another is to do ::
- >>> d = sorted(foo().items())
+ >>> d = sorted(foo())
>>> d
- [('Harry', 'broomstick'), ('Hermione', 'hippogryph')]
+ ['Harry', 'Hermione']
+
+.. note::
+
+ Before Python 3.6, when printing a dict, Python did not guarantee that
+ the key-value pairs was printed in any particular order.
There are others, but you get the idea.