mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
Fix tests breaking due to pytest mock
Release 1.12.0 of pytest-mock now raises an error on context manager usage. See https://github.com/pytest-dev/pytest-mock/blob/master/CHANGELOG.rst#1120-2019-11-19
This commit is contained in:
parent
54b8cab133
commit
af5374a386
2 changed files with 16 additions and 16 deletions
|
@ -33,7 +33,7 @@ def test_read_file_missing_file():
|
||||||
def test_read_file_cannot_read_ioerror(test_file, mocker):
|
def test_read_file_cannot_read_ioerror(test_file, mocker):
|
||||||
error = "foobar"
|
error = "foobar"
|
||||||
|
|
||||||
with mocker.patch("__builtin__.open", side_effect=IOError(error)):
|
mocker.patch("__builtin__.open", side_effect=IOError(error))
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
read_file(str(test_file))
|
read_file(str(test_file))
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ def test_read_json(test_json):
|
||||||
def test_read_json_cannot_read(test_json, mocker):
|
def test_read_json_cannot_read(test_json, mocker):
|
||||||
error = "foobar"
|
error = "foobar"
|
||||||
|
|
||||||
with mocker.patch("json.loads", side_effect=ValueError(error)):
|
mocker.patch("json.loads", side_effect=ValueError(error))
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
read_json(str(test_json))
|
read_json(str(test_json))
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ def test_write_to_new_file(tmp_path):
|
||||||
def test_write_to_existing_file_bad_perms(test_file, mocker):
|
def test_write_to_existing_file_bad_perms(test_file, mocker):
|
||||||
error = "foobar"
|
error = "foobar"
|
||||||
|
|
||||||
with mocker.patch("__builtin__.open", side_effect=IOError(error)):
|
mocker.patch("__builtin__.open", side_effect=IOError(error))
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
write_to_file(str(test_file), "yolo\nswag")
|
write_to_file(str(test_file), "yolo\nswag")
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ def text_write_list_to_json(tmp_path):
|
||||||
def test_write_to_json_bad_perms(test_json, mocker):
|
def test_write_to_json_bad_perms(test_json, mocker):
|
||||||
error = "foobar"
|
error = "foobar"
|
||||||
|
|
||||||
with mocker.patch("__builtin__.open", side_effect=IOError(error)):
|
mocker.patch("__builtin__.open", side_effect=IOError(error))
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
write_to_json(str(test_json), {"a": 1})
|
write_to_json(str(test_json), {"a": 1})
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ def test_remove_file(test_file):
|
||||||
def test_remove_file_bad_perms(test_file, mocker):
|
def test_remove_file_bad_perms(test_file, mocker):
|
||||||
error = "foobar"
|
error = "foobar"
|
||||||
|
|
||||||
with mocker.patch("os.remove", side_effect=OSError(error)):
|
mocker.patch("os.remove", side_effect=OSError(error))
|
||||||
with pytest.raises(MoulinetteError) as exception:
|
with pytest.raises(MoulinetteError) as exception:
|
||||||
rm(str(test_file))
|
rm(str(test_file))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue