unitests don't run under pdb

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Amit Gupta

    unitests don't run under pdb

    Hi

    I have a unitest file: If I do

    python testname.py : the unitests runs as usual and I get the
    following results:
    ----------------------------------------------------------------------
    Ran 2 tests in 0.024s

    OK
    --------------------------------------------------------------------

    However, if I do "python -m pdb testnames.py": I get
    ython -m pdb testnames.py
    /s/nd6/amit/pyiglu/testnames.py(1) <module>()
    -import unittest
    (Pdb) c

    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s

    OK
    -------------------------------------------------------------------



    Anything else, I should be doing (python version 2.5.1)


    Thanks!!
  • Miki

    #2
    Re: unitests don't run under pdb

    Hello Amit,
    python testname.py : the unitests runs as usual and I get the
    following results:
    ----------------------------------------------------------------------
    Ran 2 tests in 0.024s
    >
    OK
    --------------------------------------------------------------------
    >
    However, if I do "python -m pdb testnames.py": I get
    ython -m pdb testnames.py/s/nd6/amit/pyiglu/testnames.py(1) <module>()
    >
    -import unittest
    (Pdb) c
    >
    ----------------------------------------------------------------------
    Ran 0 tests in 0.000s
    >
    OK
    -------------------------------------------------------------------
    IIRC unittest checks the __main__ module for tests to run. Once you
    run python with "-m pdb" the __main__ module is pdb and not your
    script.

    HTH,
    --
    Miki <miki.tebeka@gm ail.com>
    If it won't be simple, it simply won't be. [Hire me, source code]

    Comment

    • Amit Gupta

      #3
      Re: unitests don't run under pdb

      On Feb 20, 8:51 pm, Miki <miki.teb...@gm ail.comwrote:
      Hello Amit,
      >
      >
      >
      python testname.py : the unitests runs as usual and I get the
      following results:
      ----------------------------------------------------------------------
      Ran 2 tests in 0.024s
      >
      OK
      --------------------------------------------------------------------
      >
      However, if I do "python -mpdbtestnames.p y": I get
      ython -mpdbtestnames.p y/s/nd6/amit/pyiglu/testnames.py(1) <module>()
      >
      -importunittest
      (Pdb) c
      >
      ----------------------------------------------------------------------
      Ran 0 tests in 0.000s
      >
      OK
      -------------------------------------------------------------------
      >
      IIRCunittestche cks the __main__ module for tests to run. Once you
      run python with "-mpdb" the __main__ module ispdband not your
      script.
      >
      HTH,
      --
      Miki <miki.teb...@gm ail.com>http://pythonwise.blogspot.com
      Ok, Sorry for late reply on this.

      So What do I do, if my testcase if failing because of an uncaught
      exception and I want to run it in pdb.

      Thanks

      Comment

      • Gabriel Genellina

        #4
        Re: unitests don't run under pdb

        En Fri, 14 Mar 2008 17:23:14 -0200, Amit Gupta <emailamit@gmai l.com>
        escribi�:
        On Feb 20, 8:51 pm, Miki <miki.teb...@gm ail.comwrote:
        >Hello Amit,
        >>
        python testname.py : the unitests runs as usual and I get the
        following results:
        ----------------------------------------------------------------------
        Ran 2 tests in 0.024s
        >>
        OK
        --------------------------------------------------------------------
        >>
        However, if I do "python -mpdbtestnames.p y": I get
        ython -mpdbtestnames.p y/s/nd6/amit/pyiglu/testnames.py(1) <module>()
        >>
        -importunittest
        (Pdb) c
        >>
        ----------------------------------------------------------------------
        Ran 0 tests in 0.000s
        >>
        >
        So What do I do, if my testcase if failing because of an uncaught
        exception and I want to run it in pdb.
        Run your script with python -i testname.py
        If an exception occur, you'll get the Python prompt. Execute:
        pyimport pdb
        pypdb.pm()
        to enter pdb "post-mortem".

        --
        Gabriel Genellina

        Comment

        • Gabriel Genellina

          #5
          Re: unitests don't run under pdb

          En Fri, 14 Mar 2008 17:23:14 -0200, Amit Gupta <emailamit@gmai l.com>
          escribi�:
          So What do I do, if my testcase if failing because of an uncaught
          exception and I want to run it in pdb.
          Oh, sorry, my last message doesn't apply because the unittest framework
          caughts the exception.
          Looks like you have to override TestResult.addE rror and call pdb.pm()
          there.

          --
          Gabriel Genellina

          Comment

          Working...