bpo-36597: fix random doctest failure (GH-12778)

diff --git a/Doc/library/weakref.rst b/Doc/library/weakref.rst
index 40bb06a..7f3d267 100644
--- a/Doc/library/weakref.rst
+++ b/Doc/library/weakref.rst
@@ -489,11 +489,14 @@
 :const:`False`, a finalizer will be called when the program exits if it
 is still alive.  For instance
 
-    >>> obj = Object()
-    >>> weakref.finalize(obj, print, "obj dead or exiting")  #doctest:+ELLIPSIS
-    <finalize object at ...; for 'Object' at ...>
-    >>> exit()                                               #doctest:+SKIP
-    obj dead or exiting
+.. doctest::
+   :options: +SKIP
+
+   >>> obj = Object()
+   >>> weakref.finalize(obj, print, "obj dead or exiting")
+   <finalize object at ...; for 'Object' at ...>
+   >>> exit()
+   obj dead or exiting
 
 
 Comparing finalizers with :meth:`__del__` methods