From: Tom Christie Date: Thu, 4 Jul 2019 14:53:21 +0000 (+0100) Subject: Fix pytest.raises usage X-Git-Tag: 0.12.2~3^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F569%2Fhead;p=thirdparty%2Fstarlette.git Fix pytest.raises usage --- 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):