From: Antonio Larrosa Subject: Fix mock.patch with python3.4 In python 3.5, mock.patch uses create=True automatically if you are patching builtins in a module, but in python 3.4 the argument is still needed. diff --git a/tests/unit/test_base_formatter.py b/tests/unit/test_base_formatter.py index d096457..47e74a6 100644 --- a/tests/unit/test_base_formatter.py +++ b/tests/unit/test_base_formatter.py @@ -23,7 +23,7 @@ def test_start(filename): """Verify we open a new file in the start method.""" mock_open = mock.mock_open() formatter = base.BaseFormatter(options(output_file=filename)) - with mock.patch("flake8.formatting.base.open", mock_open): + with mock.patch("flake8.formatting.base.open", mock_open, create=True): formatter.start() if filename is None: diff --git a/tests/unit/test_debug.py b/tests/unit/test_debug.py index 2da4bf8..074b409 100644 --- a/tests/unit/test_debug.py +++ b/tests/unit/test_debug.py @@ -95,7 +95,7 @@ def test_information(system, pyversion, pyimpl): system.assert_called_once_with() -@mock.patch("flake8.main.debug.print") +@mock.patch("flake8.main.debug.print", create=True) @mock.patch("flake8.main.debug.information", return_value={}) @mock.patch("json.dumps", return_value="{}") def test_print_information_no_plugins(dumps, information, print_mock): @@ -112,7 +112,7 @@ def test_print_information_no_plugins(dumps, information, print_mock): assert print_mock.called is False -@mock.patch("flake8.main.debug.print") +@mock.patch("flake8.main.debug.print", create=True) @mock.patch("flake8.main.debug.information", return_value={}) @mock.patch("json.dumps", return_value="{}") def test_print_information(dumps, information, print_mock):