def test_plot_graph(excel, tmpdir): from unittest import mock excel_compiler = ExcelCompiler(excel=excel) with pytest.raises(ImportError, match="Package 'matplotlib' is not installed"): excel_compiler.plot_graph() import sys mock_imports = ( 'matplotlib', 'matplotlib.pyplot', 'matplotlib.cbook', 'matplotlib.colors', 'matplotlib.collections', 'matplotlib.patches', ) for mock_import in mock_imports: sys.modules[mock_import] = mock.MagicMock() out_address = 'trim-range!B2' excel_compiler.evaluate(out_address) with mock.patch('pycel.excelcompiler.nx'): excel_compiler.plot_graph()