allowing output of code that is unittested?

Discussion in 'Python' started by per, Jul 15, 2009.

  1. per

    per Guest

    hi all,

    i am using the standard unittest module to unit test my code. my code
    contains several print statements which i noticed are repressed when i
    call my unit tests using:

    if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestMyCode)
    unittest.TextTestRunner(verbosity=2).run(suite)

    is there a way to allow all the print statements in the code that is
    being run by the unit test functions to be printed to stdio? i want
    to be able to see the output of the tested code, in addition to the
    output of the unit testing framework.

    thank you.
     
    per, Jul 15, 2009
    #1
    1. Advertising

  2. per schrieb:
    > hi all,
    >
    > i am using the standard unittest module to unit test my code. my code
    > contains several print statements which i noticed are repressed when i
    > call my unit tests using:
    >
    > if __name__ == '__main__':
    > suite = unittest.TestLoader().loadTestsFromTestCase(TestMyCode)
    > unittest.TextTestRunner(verbosity=2).run(suite)
    >
    > is there a way to allow all the print statements in the code that is
    > being run by the unit test functions to be printed to stdio? i want
    > to be able to see the output of the tested code, in addition to the
    > output of the unit testing framework.



    I use nosetests to discover & run tests, and that has an "-s"-option
    that does exactly that.

    Diez
     
    Diez B. Roggisch, Jul 15, 2009
    #2
    1. Advertising

  3. per wrote:
    > i am using the standard unittest module to unit test my code. my code
    > contains several print statements which i noticed are repressed when i
    > call my unit tests using:
    >
    > if __name__ == '__main__':
    > suite = unittest.TestLoader().loadTestsFromTestCase(TestMyCode)
    > unittest.TextTestRunner(verbosity=2).run(suite)


    I have here

    if __name__ == '__main__':
    unittest.main()

    preceded by classes which derive from unittest.TestCase. Running this allows
    me to write to stdout using print as usual, even though it's ugly because
    it clutters the output of the testcases.

    Uli

    --
    Sator Laser GmbH
    Geschäftsführer: Thorsten Föcking, Amtsgericht Hamburg HR B62 932
     
    Ulrich Eckhardt, Jul 16, 2009
    #3
    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. VMDD Tech - powered by sockSvr

    [ANN] j2Perl 2.0 - Allowing Java to access Perl code

    VMDD Tech - powered by sockSvr, Mar 3, 2005, in forum: Perl
    Replies:
    1
    Views:
    837
    Philip Salgannik
    Mar 4, 2005
  2. ack95
    Replies:
    0
    Views:
    548
    ack95
    Mar 3, 2006
  3. VMDD Tech - powered by sockSvr

    [ANN] j2Perl 2.0 - Allowing Java to access Perl code

    VMDD Tech - powered by sockSvr, Mar 3, 2005, in forum: Java
    Replies:
    1
    Views:
    324
    Philip Salgannik
    Mar 4, 2005
  4. Enquiries, Hopkins Research
    Replies:
    11
    Views:
    622
    Ismail Pazarbasi
    Oct 29, 2005
  5. Replies:
    1
    Views:
    344
    Ben Rush
    Apr 3, 2007
Loading...

Share This Page