@@ -715,36 +715,51 @@ above.
715
715
An example's doctest directives modify doctest's behavior for that single
716
716
example. Use ``+ `` to enable the named behavior, or ``- `` to disable it.
717
717
718
- For example, this test passes::
718
+ For example, this test passes:
719
719
720
- >>> print(list(range(20))) # doctest: +NORMALIZE_WHITESPACE
720
+ .. doctest ::
721
+ :no-trim-doctest-flags:
722
+
723
+ >>> print (list (range (20 ))) # doctest: +NORMALIZE_WHITESPACE
721
724
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
722
725
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
723
726
724
727
Without the directive it would fail, both because the actual output doesn't have
725
728
two blanks before the single-digit list elements, and because the actual output
726
729
is on a single line. This test also passes, and also requires a directive to do
727
- so::
730
+ so:
731
+
732
+ .. doctest ::
733
+ :no-trim-doctest-flags:
728
734
729
- >>> print(list(range(20))) # doctest: +ELLIPSIS
735
+ >>> print (list (range (20 ))) # doctest: +ELLIPSIS
730
736
[0, 1, ..., 18, 19]
731
737
732
738
Multiple directives can be used on a single physical line, separated by
733
- commas::
739
+ commas:
734
740
735
- >>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
741
+ .. doctest ::
742
+ :no-trim-doctest-flags:
743
+
744
+ >>> print (list (range (20 ))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
736
745
[0, 1, ..., 18, 19]
737
746
738
747
If multiple directive comments are used for a single example, then they are
739
- combined::
748
+ combined:
749
+
750
+ .. doctest ::
751
+ :no-trim-doctest-flags:
740
752
741
- >>> print(list(range(20))) # doctest: +ELLIPSIS
742
- ... # doctest: +NORMALIZE_WHITESPACE
753
+ >>> print (list (range (20 ))) # doctest: +ELLIPSIS
754
+ ... # doctest: +NORMALIZE_WHITESPACE
743
755
[0, 1, ..., 18, 19]
744
756
745
757
As the previous example shows, you can add ``... `` lines to your example
746
758
containing only directives. This can be useful when an example is too long for
747
- a directive to comfortably fit on the same line::
759
+ a directive to comfortably fit on the same line:
760
+
761
+ .. doctest ::
762
+ :no-trim-doctest-flags:
748
763
749
764
>>> print (list (range (5 )) + list (range (10 , 20 )) + list (range (30 , 40 )))
750
765
... # doctest: +ELLIPSIS
@@ -784,18 +799,23 @@ instead. Another is to do ::
784
799
785
800
There are others, but you get the idea.
786
801
787
- Another bad idea is to print things that embed an object address, like ::
802
+ Another bad idea is to print things that embed an object address, like
803
+
804
+ .. doctest ::
788
805
789
- >>> id(1.0) # certain to fail some of the time
806
+ >>> id (1.0 ) # certain to fail some of the time # doctest: +SKIP
790
807
7948648
791
808
>>> class C : pass
792
- >>> C() # the default repr() for instances embeds an address
793
- <__main__.C instance at 0x00AC18F0>
809
+ >>> C() # the default repr() for instances embeds an address # doctest: +SKIP
810
+ <C object at 0x00AC18F0>
811
+
812
+ The :const: `ELLIPSIS ` directive gives a nice approach for the last example:
794
813
795
- The :const: `ELLIPSIS ` directive gives a nice approach for the last example::
814
+ .. doctest ::
815
+ :no-trim-doctest-flags:
796
816
797
- >>> C() # doctest: +ELLIPSIS
798
- <__main__.C instance at 0x...>
817
+ >>> C() # doctest: +ELLIPSIS
818
+ <C object at 0x...>
799
819
800
820
Floating-point numbers are also subject to small output variations across
801
821
platforms, because Python defers to the platform C library for float formatting,
0 commit comments