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, 2019 in Python by ana1504.k
• 7,910 points
485 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, 2019 by SDeb
• 13,300 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
27,374 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 aryya
• 7,450 points
850 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
• 58,090 points
9,494 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
• 58,090 points
1,506 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,560 points
1,040 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,023 views
0 votes
1 answer
0 votes
1 answer

python JSON only get keys in first level

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

answered Jan 22, 2019 in Python by SDeb
• 13,300 points
22,195 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP