I am testing my module using a library unittest. This includes charting using the library matplotlib. The problem at the moment is that testing is paused every time the chart is applied to the chart, and it resumes only after the chart is closed. How can i avoid this?
unittest
matplotlib
I will model my answer after a simple code example from the matplotlib tutorial: http://matplotlib.org/users/pyplot_tutorial.html
Suppose we are testing the following module plot_graph.py::
plot_graph.py
import matplotlib.pyplot as plt def func_plot(): plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() if __name__ == "__main__": func_plot()
show :
show
from plot_graph import func_plot from unittest.mock import patch @patch("plot_graph.plt.show") def test_plot(mock_show): assert func_plot() == None
, pyplot.show(). : https://docs.python.org/3/library/unittest.mock.html.
pyplot.show()
, : https://docs.python.org/3/library/unittest.mock.html#where-to-patch
, : nosetests matplotlib?
pyplot.show(), . , block=False show.
block=False
Instead of hacking, you can try to use the principle of single responsibility from SOLID and write test code so that you do not encounter such problems. Just an idea ...
Source: https://habr.com/ru/post/1015989/More articles:Apache spark error: not found: sqlContext value - scalaEntity database engine updates many for many - asp.net-coreTesting with TestBed: No Provider for StatusBar Error - angularHow to use Basic auth in swagger ui v.3.0 - swagger-uiWhat does in Proguard warped traffic? - deobfuscationискры в windows:: 16: ошибка: не найден: значение sqlContext - javaTFS 2017 Build автоматически запускается и продолжает сбой - gitHow to focus on the field? - angularThe child inside NestedScrollView does not cover the entire height of the screen - androidPreloading background images - javascriptAll Articles