<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>momijiame</author_name>
  <author_url>https://blog.hatena.ne.jp/momijiame/</author_url>
  <blog_title>CUBE SUGAR CONTAINER</blog_title>
  <blog_url>https://blog.amedama.jp/</blog_url>
  <categories>
    <anon>FastAPI</anon>
    <anon>pytest</anon>
    <anon>uv</anon>
    <anon>Python</anon>
  </categories>
  <description>Web アプリケーションの例外ハンドリングでは、未処理の例外はキャッチして特定の HTTP レスポンスに変換するのが定石だろう。 このとき、未処理の例外をキャッチして HTTP レスポンスに変換する仕組みは例外ハンドラと呼ばれることが多い。 そして、FastAPI にも例外ハンドラの仕組みが用意されている。 fastapi.tiangolo.com 今回は例外ハンドラの振る舞いを pytest を使ってユニットテストする方法について書いてみる。 なお、FastAPI を使ったプロジェクトのユニットテストに関する基本的な内容は以下に書いた。 blog.amedama.jp 使った環境は次のとおり…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fblog.amedama.jp%2Fentry%2Ffast-api-pytest-exception-handler&quot; title=&quot;Python: FastAPI の例外ハンドラを pytest でテストする - CUBE SUGAR CONTAINER&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://m.media-amazon.com/images/I/51kU2EFP5UL._SL500_.jpg</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2026-02-27 08:00:00</published>
  <title>Python: FastAPI の例外ハンドラを pytest でテストする</title>
  <type>rich</type>
  <url>https://blog.amedama.jp/entry/fast-api-pytest-exception-handler</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
