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

  • SEARCH
  • Home
  • 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 6599517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:30:04+00:00 2026-05-25T18:30:04+00:00

I am using PyDev for development and unit-testing of my Python application. As for

  • 0

I am using PyDev for development and unit-testing of my Python application.
As for unit-testing, everything works great except the fact that no content is logged to the logging framework. The logger is not captured by the “Captured output” of PyDev.

I’m already forwarding everything logged to the standard output like this:

import sys
logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))

Nevertheless the “Captured output” does not display the stuff logged to loggers.

Here’s an example unittest-script: test.py

import sys
import unittest
import logging

logger = logging.getLogger()
logger.level = logging.DEBUG
logger.addHandler(logging.StreamHandler(sys.stdout))

class TestCase(unittest.TestCase):
    def testSimpleMsg(self):
        print("AA")
        logging.getLogger().info("BB")

The console output is:

Finding files... done.
Importing test modules ... done.

testSimpleMsg (itf.lowlevel.tests.hl7.TestCase) ... AA
2011-09-19 16:48:00,755 - root - INFO - BB
BB
ok

----------------------------------------------------------------------
Ran 1 test in 0.001s

OK

But the CAPTURED OUTPUT for the test is:

======================== CAPTURED OUTPUT =========================
AA

Does anybody know how to capture everything that is logged to a logging.Logger during the execution of this test?

  • 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-05-25T18:30:05+00:00Added an answer on May 25, 2026 at 6:30 pm

    The issue is that the unittest runner replaces sys.stdout/sys.stderr before the testing starts, and the StreamHandler is still writing to the original sys.stdout.

    If you assign the ‘current’ sys.stdout to the handler, it should work (see the code below).

    import sys
    import unittest
    import logging
    
    logger = logging.getLogger()
    logger.level = logging.DEBUG
    stream_handler = logging.StreamHandler(sys.stdout)
    logger.addHandler(stream_handler)
    
    class TestCase(unittest.TestCase):
        def testSimpleMsg(self):
            stream_handler.stream = sys.stdout
            print("AA")
            logging.getLogger().info("BB")
    

    Although, a better approach would be adding/removing the handler during the test:

    import sys
    import unittest
    import logging
    
    logger = logging.getLogger()
    logger.level = logging.DEBUG
    
    class TestCase(unittest.TestCase):
        def testSimpleMsg(self):
            stream_handler = logging.StreamHandler(sys.stdout)
            logger.addHandler(stream_handler)
            try:
                print("AA")
                logging.getLogger().info("BB")
            finally:
                logger.removeHandler(stream_handler)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unit-testing my python code in eclipse using PyDev unit-testing. I right click
I'm using Eclipse on Windows, with the PyDev plugin for Python development. When I
I am using eclipse pydev IDE for coding python. I found that by default
I'm using Eclipse / PyDev trying to find a way to debug code that
I have been using NotePAD++ for editing Python scripts. I recently downloaded the PyDEV
I'm using PyDev with Django. The autocomplete works nicely in the shell - I
I am now moving to eclipse for my python development. I have pydev installed
I'm using pylint + pydev, with python 2.6. I have a module with just
I'm going through Django tutorial and using PyDev Eclipse plugin for development. For interactive
I created a Django application, it works fine on my machine. After that I

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.