diff --git a/tests/test_json_async.py b/tests/test_json_async.py index e8dacdc..9a47cbc 100644 --- a/tests/test_json_async.py +++ b/tests/test_json_async.py @@ -1,4 +1,8 @@ -from json import JSONDecodeError, dumps +try: + from ujson import JSONDecodeError, dumps +except ImportError: + from json import dumps, JSONDecodeError + from pathlib import Path from typing import Any, Union @@ -29,13 +33,13 @@ async def test_json_read_valid(path: Union[str, Path], expected: Any): @pytest.mark.parametrize( "path, expected", [ - ("tests/data/invalid.json", pytest.raises(JSONDecodeError)), - ("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)), + ("tests/data/invalid.json", JSONDecodeError), + ("tests/data/nonexistent.json", FileNotFoundError), ], ) async def test_json_read_invalid(path: Union[str, Path], expected: Any): - with expected: - assert await json_read(path) == expected + with pytest.raises(expected): + await json_read(path) @pytest.mark.asyncio diff --git a/tests/test_json_sync.py b/tests/test_json_sync.py index 88765c9..65b519d 100644 --- a/tests/test_json_sync.py +++ b/tests/test_json_sync.py @@ -1,4 +1,8 @@ -from json import JSONDecodeError, dumps +try: + from ujson import JSONDecodeError, dumps +except ImportError: + from json import dumps, JSONDecodeError + from pathlib import Path from typing import Any, Union @@ -27,12 +31,12 @@ def test_json_read_valid(path: Union[str, Path], expected: Any): @pytest.mark.parametrize( "path, expected", [ - ("tests/data/invalid.json", pytest.raises(JSONDecodeError)), - ("tests/data/nonexistent.json", pytest.raises(FileNotFoundError)), + ("tests/data/invalid.json", JSONDecodeError), + ("tests/data/nonexistent.json", FileNotFoundError), ], ) def test_json_read_invalid(path: Union[str, Path], expected: Any): - with expected: + with pytest.raises(expected): assert sync.json_read(path) == expected