Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:19:39+00:00 2026-06-17T08:19:39+00:00

In the unittest docs [ http://docs.python.org/2/library/unittest.html#unittest.main ], I see the following method signature described:

  • 0

In the unittest docs [ http://docs.python.org/2/library/unittest.html#unittest.main ], I see the following method signature described:

unittest.main([module[, defaultTest[, argv[, testRunner[, testLoader[, exit[, verbosity[, failfast[, catchbreak[, buffer]]]]]]]]]])

The last option is “buffer”. The docs explain the following about this option:

The failfast, catchbreak and buffer parameters have the same effect as the same-name command-line options.

The docs for the command-line options [ http://docs.python.org/2/library/unittest.html#command-line-options ] explain ‘buffer’ as follows:

-b, –buffer
The standard output and standard error streams are buffered during the test run. Output during a passing test is discarded. Output is echoed normally on test fail or error and is added to the failure messages.

I have the following demo code which does not exhibit the behavior that would be expected:

import unittest2

class DemoTest(unittest2.TestCase):
    def test_one(self):
        self.assertTrue(True)

    def test_two(self):
        self.assertTrue(True)

if __name__ == '__main__':
    test_program = unittest2.main(verbosity=0, buffer=True, exit=False)

The output of this program is:

----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK

In fact, I get the same output if I chang the last line in my program to:

test_program = unittest2.main(verbosity=0, buffer="hello", exit=False)

What am I doing wrong? (I tried using unittest instead of unittest2, but it made no difference.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:19:40+00:00Added an answer on June 17, 2026 at 8:19 am

    The point is that buffer option affects stdout writing inside your tests, ignoring that of unittest2 behaviour. That is to say, you will see the difference, if you add string like

    print "Suppress me!"
    

    to any test method, this expression will appear on stdout, if you choose buffer=False, while it will be suppressed if you set it to True.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reference - http://docs.python.org/library/unittest.html#assert-methods assertEqual(a, b) # checks that a == b assertIs(a, b) #
I have been reading: http://static.springsource.org/spring/docs/2.5.x/reference/resources.html But am having difficulty understanding how to specify classpath
I know about unittest Python module. I know about assertRaises() method of TestCase class.
I use Python's unittest module and want to check if two complex data structures
When running a unittest, I receive the following Exception: Test method threw exception: System.MissingMethodException:
I am trying to use python's unittest library to write some unit tests. I
I would like my Python unittest module to tell the test runner to skip
I want to check for an exception in Python unittest, with the following requirements:
Possible Duplicate: Python unittest - invoke unittest.main() with a custom TestSuite I have a
The Python documentation for unittest implies that the assertRaises() method can be used as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.