From ca65c9b5cae56910cc1025f76271424d8bdd4e8b Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 4 Jul 2019 15:53:21 +0100 Subject: [PATCH] Fix pytest.raises usage --- tests/test_responses.py | 8 ++++---- tests/test_staticfiles.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/test_responses.py b/tests/test_responses.py index f90bde48..f45a447d 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -188,18 +188,18 @@ def test_file_response(tmpdir): def test_file_response_with_directory_raises_error(tmpdir): app = FileResponse(path=tmpdir, filename="example.png") client = TestClient(app) - with pytest.raises(RuntimeError) as exc: + with pytest.raises(RuntimeError) as exc_info: client.get("/") - assert "is not a file" in str(exc) + assert "is not a file" in str(exc_info.value) def test_file_response_with_missing_file_raises_error(tmpdir): path = os.path.join(tmpdir, "404.txt") app = FileResponse(path=path, filename="404.txt") client = TestClient(app) - with pytest.raises(RuntimeError) as exc: + with pytest.raises(RuntimeError) as exc_info: client.get("/") - assert "does not exist" in str(exc) + assert "does not exist" in str(exc_info.value) def test_set_cookie(): diff --git a/tests/test_staticfiles.py b/tests/test_staticfiles.py index 142b8f65..13d0703a 100644 --- a/tests/test_staticfiles.py +++ b/tests/test_staticfiles.py @@ -65,19 +65,19 @@ def test_staticfiles_with_missing_file_returns_404(tmpdir): def test_staticfiles_instantiated_with_missing_directory(tmpdir): - with pytest.raises(RuntimeError) as exc: + with pytest.raises(RuntimeError) as exc_info: path = os.path.join(tmpdir, "no_such_directory") StaticFiles(directory=path) - assert "does not exist" in str(exc) + assert "does not exist" in str(exc_info.value) def test_staticfiles_configured_with_missing_directory(tmpdir): path = os.path.join(tmpdir, "no_such_directory") app = StaticFiles(directory=path, check_dir=False) client = TestClient(app) - with pytest.raises(RuntimeError) as exc: + with pytest.raises(RuntimeError) as exc_info: client.get("/example.txt") - assert "does not exist" in str(exc) + assert "does not exist" in str(exc_info.value) def test_staticfiles_configured_with_file_instead_of_directory(tmpdir): @@ -87,9 +87,9 @@ def test_staticfiles_configured_with_file_instead_of_directory(tmpdir): app = StaticFiles(directory=path, check_dir=False) client = TestClient(app) - with pytest.raises(RuntimeError) as exc: + with pytest.raises(RuntimeError) as exc_info: client.get("/example.txt") - assert "is not a directory" in str(exc) + assert "is not a directory" in str(exc_info.value) def test_staticfiles_config_check_occurs_only_once(tmpdir): -- 2.47.2