Change log-level via mocking

0 votes
How do I change the log-level temporarily?

I am using mocking as of now

with mock.patch(...):
    my_method_which_does_log()
All logging.info() calls inside the method should get ignored and not logged to the console.

How to implement the (...) to make logs of level INFO get ignored?

The code is single-process and single-thread and executed during testing only. Can anyone help me with this issue?
Jun 4 in Python by ana1504.k
• 6,710 points
9 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

A way to do this without mocking is logging.disable. You can try the following:

class TestSomething(unittest.TestCase):
    def setUp(self):
        logging.disable(logging.WARNING)

    def tearDown(self):
        logging.disable(logging.NOTSET)
answered Jun 4 by SDeb
• 10,860 points

Related Questions In Python

+2 votes
6 answers

How can I change directory or "cd" in Python?

Context Manager: cd import os class cd:     """Context manager for ...READ MORE

answered Oct 18, 2018 in Python by Nabarupa
58 views
0 votes
1 answer

Python using basicConfig method to log to console and file

I can't reproduce it on Python 3.3. ...READ MORE

answered Aug 14, 2018 in Python by ariaholic
• 7,320 points
27 views
0 votes
1 answer

Python using basicConfig method to log to console and file

Try this working fine(tested in python 2.7) ...READ MORE

answered Aug 27, 2018 in Python by Priyaj
• 56,140 points
469 views
0 votes
1 answer

Know/change current directory in Python shell?

This will work  >>> import os >>> os.getcwd() '/home/user' >>> os.chdir("/tmp/") >>> ...READ MORE

answered Nov 12, 2018 in Python by Priyaj
• 56,140 points
18 views
0 votes
1 answer

How to change one character in a string in Python?

Python strings are immutable, you change them ...READ MORE

answered Dec 4, 2018 in Python by Nymeria
• 3,500 points
29 views
0 votes
1 answer

how can i count the items in a list?

suppose you have a list a = [0,1,2,3,4,5,6,7,8,9,10] now ...READ MORE

answered May 2 in Python by Mohammad
• 1,400 points
56 views
0 votes
1 answer

python JSON only get keys in first level

You just need a simple .keys() >>> dct ...READ MORE

answered Jan 22 in Python by SDeb
• 10,860 points
337 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.