def test_gen_dot(excel, tmpdir): from unittest import mock excel_compiler = ExcelCompiler(excel=excel) with pytest.raises(ImportError, match="Package 'pydot' is not installed"): excel_compiler.export_to_dot() import sys mock_imports = ( 'pydot', ) for mock_import in mock_imports: sys.modules[mock_import] = mock.MagicMock() with mock.patch('networkx.drawing.nx_pydot.write_dot'): excel_compiler.export_to_dot()