Skip to content

Instantly share code, notes, and snippets.

@brandon-rhodes
Created July 12, 2018 08:51
Show Gist options
  • Save brandon-rhodes/4d240eb10160ea8543a988b062c2ea3c to your computer and use it in GitHub Desktop.
Save brandon-rhodes/4d240eb10160ea8543a988b062c2ea3c to your computer and use it in GitHub Desktop.
Make Sphinx doctest insensitive to object address differences
# 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