Invisible differences in doctestsΒΆ

Tags: python

I had some weird test error yesterday on a library that tested just fine for others. It was a test that tested a testrunner. “Got this but expected that”. Which is weird as “this” and “that” looked the same. So I added doctest.REPORT_NDIFF to the doctest optionflags to get more details:

Differences (ndiff with -expected +actual):
      Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
  -   Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
  +   Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
  ? ++++++++
      Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
    Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
    False

So what? Those lines look the same. And I checked for a spaces/tabs problem: no. In the end I found the difference by piping the output to a text file and opening it with emacs:

Differences (ndiff with -expected +actual):
      Set up zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
  -   Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
  + ^[[?1034h  Ran 2 tests with 0 failures and 0 errors in N.NNN seconds.
  ? +++++++++
      Tear down zope.testing.testrunner.layer.UnitTests in N.NNN seconds.
    Total: 4 tests, 0 failures, 0 errors in N.NNN seconds.
    False

Ah, what is that ^[[?1034h doing in there? Probably a terminal escape code or so. 8th bit on terminfo stuff apparently. And probably triggered by import readline on some machines according to this bug report.

The tests actually run buildout inside them so buildout (or one of the recipes) does an import... I’ll have to figure out how to work around that. If someone has a ready-made fix, please mail me :-)

UPDATE: I’ve figured out a hack to work around the issue.

blog comments powered by Disqus
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):