Skip to content

Commit a59a1a9

Browse files
committed
Compute the arguments before the pytest.raises block
Four tests built an argument inside the block, so a failure there would have been read as the call under test raising. The value is now prepared first, leaving one call that can throw.
1 parent 83646ca commit a59a1a9

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

test/test_json_utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,6 @@ def test_read_empty_file_returns_none(self, tmp_path):
4545
def test_read_invalid_json_raises(self, tmp_path):
4646
path = tmp_path / "bad.json"
4747
path.write_text("{invalid json", encoding="utf-8")
48+
target = str(path)
4849
with pytest.raises(JEditorJsonException):
49-
read_json(str(path))
50+
read_json(target)

test/test_plugin_download.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ def test_a_plain_name_lands_in_the_directory(self, tmp_path):
2828

2929
@pytest.mark.parametrize("name", ESCAPING_NAMES)
3030
def test_a_name_that_escapes_is_rejected(self, tmp_path, name):
31+
directory = str(tmp_path)
3132
with pytest.raises(ValueError):
32-
_safe_destination(str(tmp_path), name)
33+
_safe_destination(directory, name)
3334

3435

3536
class TestDownloadingAPlugin:
@@ -47,8 +48,9 @@ def test_a_plain_name_is_written(self, tmp_path):
4748
def test_an_escaping_name_writes_nothing(self, tmp_path, name):
4849
destination = tmp_path / "plugins"
4950
destination.mkdir()
51+
directory = str(destination)
5052
with pytest.raises(ValueError):
51-
download_plugin_file("https://example.invalid/x.py", str(destination), name)
53+
download_plugin_file("https://example.invalid/x.py", directory, name)
5254
assert list(tmp_path.rglob("*.py")) == []
5355

5456

test/test_text_codec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ def test_undecodable_bytes_fall_back_instead_of_failing(self):
8888
assert isinstance(text, str) and encoding in {"utf-8", "latin-1"}
8989

9090
def test_explicit_encoding_that_cannot_decode_raises(self):
91+
encoded = "中文".encode("big5")
9192
with pytest.raises(UnicodeDecodeError):
92-
decode_bytes("中文".encode("big5"), "ascii")
93+
decode_bytes(encoded, "ascii")
9394

9495
def test_bom_detection_without_a_bom(self):
9596
assert encoding_from_bom(b"plain") is None

0 commit comments

Comments
 (0)