very puzzling doctest behaviour

André andre.roberge at gmail.com
Mon Dec 17 19:25:53 EST 2007


Hi everyone,

I've run into a very puzzling doctest behaviour - I'm trying to narrow
down the case of it but I'm dealing with multiple files being imported
for one of the case and I have not, so far, created a simple example.
However, just in case someone had run into something similar, I
thought I would ask.

I am using the doctest.testfile() interface to load up tests that
resides in a text file.  Here's a description of the puzzling feature.

==== file 1: all tests pass ====
title
  >>> print "<"
  <
  >>> import module_a
  >>> print "<"
  <
========================

So far, nothing surprising...

==== file 2: we have a failure ====
title
  >>> print "<"
  <
  >>> import module_a
  >>> print "<"
  <

+ 400 lines of text and further tests
========================
The second expected "<" fails; instead, we get "<"

==== file 3: all tests pass ====
title
  >>> print "<"
  <
  >>> import module_a
  >>> print "<"
  <

+ 400 lines of text and further tests
========================

Upon further inspection, I find in module_a that, if I comment out a
line like
import module_b
then, tests in file 2 pass again.   So, I figure the problem is in
module_b.
I then did

==== file 4: one failure ====
title
  >>> print "<"
  <
  >>> import module_b
  >>> print "<"
  <

+ 400 lines of text and further tests
========================

Again, this can be "fixed" by changing the expected output of the
second test

==== file 5: no failure ====
title
  >>> print "<"
  <
  >>> import module_b
  >>> print "<"
  <

+ 400 lines of text and further tests
========================

As mentioned, I have not succeeded in narrowing it down further.
However, has anyone observed such a behaviour of doctests before?


André



More information about the Python-list mailing list