How to run nosetests without displaying my matplotlib graph?

I am trying to run my test without displaying messages from my main program. I only need detailed messages from the media for display.

For example:

nosetests -v --nologcapture

All my printed messages from my main program will disappear.

However, the graph that I call in my main program ( plt.show()from matplotlib) is still displayed.

How to run tests without showing matplotlib graph?

+4
source share
1 answer

, unittests , python Mock. , "plt.show()", , .

unittests:

from mock import patch


... unittest boiler plate stuff ...

@patch("matplotlib.pyplot.show")
def testMyCode(self, mock_show):
    mock_show.return_value = None  #probably not necessary here in your case
    ... rest of test code ...

"patch" show "mock_show", . ​​ .

+5

Source: https://habr.com/ru/post/1015995/


All Articles