How do I prevent nosetests from interspersing logging output inside the output from its tests? I've just adding logging to my Django code like this:
import logging
logger = logging.getLogger(__name__)
def home_page(request, template):
device = get_device_capabilities(request)
device_type = get_device_type(device)
logger.info("device_type = " + device_type)
logger.info("screen_width = " + str(screen_width))
When I run the tests like this:
nosetests --nocapture
I get this:
[04/15/2014 02:42:57 PM] INFO [apps.home.views:24] device_type = computer
[04/15/2014 02:42:57 PM] INFO [apps.home.views:25] screen_width = 800
....................................................................................................................................................................................................................................
----------------------------------------------------------------------
Ran 230 tests in 42.521s
OK
I'm just getting started with raising exceptions and logging information and I certainly don't want my test output littered with the output from my logger statements. I thought the "--nocapture" flag was supposed to prevent this. I've skimmed all the nosetest documentation and didn't see anything else that would help. Am I missing something? Is there a way to stop nosetests from including my logger messages in its output?
Thanks!
Thanks to those who provided an answer to my question. I chose not to implement @amezhenin's solution as it was too different from how I run my tests and I didn't want to change. @Oleksiy's solutions got rid of some logging messages but not all of them. I didn't quite get what @gardenunez was getting at but that's my fault.
After more research, I realized that I was specifying the nosetest argument incorrectly. It's not --nocapture
as I indicated in my initial question but rather --nologcapture
. When I specified this argument, all of my logging messages were hidden.