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
• 7,870 points
14 views

1 answer to this question.

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
• 13,160 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
88 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,340 points
38 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,520 points
752 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,520 points
30 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,520 points
50 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 175 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
• 13,160 points
826 views