Created
July 12, 2018 08:51
-
-
Save brandon-rhodes/4d240eb10160ea8543a988b062c2ea3c to your computer and use it in GitHub Desktop.
Make Sphinx doctest insensitive to object address differences
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Append this to the `conf.py` file at the root of your Sphinx project | |
# that is already using the `sphinx.ext.doctest` extension: | |
import doctest | |
import re | |
import sphinx.ext.doctest as ext_doctest | |
ADDRESS_RE = re.compile(r'\b0x[0-9a-f]{1,16}\b') | |
class BetterDocTestRunner(ext_doctest.SphinxDocTestRunner): | |
def __init__(self, checker=None, verbose=None, optionflags=0): | |
checker = BetterOutputChecker() | |
doctest.DocTestRunner.__init__(self, checker, verbose, optionflags) | |
class BetterOutputChecker(doctest.OutputChecker): | |
def check_output(self, want, got, optionflags): | |
want = ADDRESS_RE.sub('0x7f00ed991e80', want) | |
got = ADDRESS_RE.sub('0x7f00ed991e80', got) | |
return doctest.OutputChecker.check_output(self, want, got, optionflags) | |
ext_doctest.SphinxDocTestRunner = BetterDocTestRunner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment