very puzzling doctest behaviour

Discussion in 'Python' started by André, Dec 18, 2007.

  1. André

    André Guest

    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 "&lt;"

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

    <
    >>> import module_a
    >>> print "<"

    &lt;

    + 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 "<"

    &lt;

    + 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é
    André, Dec 18, 2007
    #1
    1. Advertising

  2. André

    André Guest

    Oops, sorry, I made an error in the original description of the
    problem (test 4 & 5 below)

    On Dec 17, 8:25 pm, "André" <> wrote:
    > 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 "&lt;"
    >
    > ==== file 3: all tests pass ====
    > title
    > >>> print "<"

    > <
    > >>> import module_a
    > >>> print "<"

    > &lt;
    >
    > + 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
    >


    Sorry, file 4 had NO failure ... so it looked like the problem was NOT
    in module_b; and yet, when I commented its import in module_a, the
    problem went away.
    > ==== file 4: one 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é
    André, Dec 18, 2007
    #2
    1. Advertising

  3. En Mon, 17 Dec 2007 21:29:55 -0300, André <>
    escribió:

    >> 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.
    >>
    >> The second expected "<" fails; instead, we get "&lt;"
    >>
    >> ==== file 3: all tests pass ====
    >> title
    >> >>> print "<"

    >> <
    >> >>> import module_a
    >> >>> print "<"

    >> &lt;
    >>
    >> + 400 lines of text and further tests
    >> ========================


    Are you playing with sys.stdout, replacing it with another object, or
    changing its encoding? That's the only way to get "&lt;" when printing "<"
    that I can think of.

    --
    Gabriel Genellina
    Gabriel Genellina, Dec 18, 2007
    #3
  4. André

    André Guest

    On Dec 17, 11:53 pm, "Gabriel Genellina" <>
    wrote:
    > En Mon, 17 Dec 2007 21:29:55 -0300, André <>
    > escribió:
    >
    > >> 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.

    >
    > >> The second expected "<" fails; instead, we get "&lt;"

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

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

    >
    > Are you playing with sys.stdout, replacing it with another object, or
    > changing its encoding? That's the only way to get "&lt;" when printing "<"
    > that I can think of.
    >

    Hmmm, yes I do, somewhere (locally I thought) in a function embedded
    in yet another module. This gives me something to look for.

    Thanks for the suggestion.

    André


    > --
    > Gabriel Genellina
    André, Dec 18, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Radu
    Replies:
    2
    Views:
    397
  2. Sunjay Varma
    Replies:
    4
    Views:
    343
    John Roth
    Mar 10, 2011
  3. Ian Macdonald

    Puzzling regex behaviour

    Ian Macdonald, Feb 13, 2007, in forum: Ruby
    Replies:
    23
    Views:
    196
    Ian Macdonald
    Feb 16, 2007
  4. Raphael Clancy

    Puzzling behaviour with range...

    Raphael Clancy, Jan 7, 2009, in forum: Ruby
    Replies:
    5
    Views:
    90
    Dave Bass
    Jan 8, 2009
  5. Henry Law
    Replies:
    9
    Views:
    99
    Henry Law
    Sep 30, 2005
Loading...

Share This Page