]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Fix pytest.raises usage 569/head
authorTom Christie <tom@tomchristie.com>
Thu, 4 Jul 2019 14:53:21 +0000 (15:53 +0100)
committerTom Christie <tom@tomchristie.com>
Thu, 4 Jul 2019 14:53:21 +0000 (15:53 +0100)
tests/test_responses.py
tests/test_staticfiles.py

index f90bde48b41d0243521e045f1dfe313d15974197..f45a447d6b31bdb054deaa46cef0c75330017e5a 100644 (file)
@@ -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():
index 142b8f65416d16726af2d0a4b9361699d2a0d6c6..13d0703a015d2566b5cf68acce62ad9dd2bbe48f 100644 (file)
@@ -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):