<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Snapshot Testing on 每日拍拍</title>
    <link>https://dailypypy.org/tags/snapshot-testing/</link>
    <description>Recent content in Snapshot Testing on 每日拍拍</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>zh-tw</language>
    <copyright>© 2026 每日拍拍</copyright>
    <lastBuildDate>Thu, 27 Aug 2026 12:43:00 +0800</lastBuildDate><atom:link href="https://dailypypy.org/tags/snapshot-testing/index.xml" rel="self" type="application/rss+xml" />
    <follow_challenge>
      <feedId>155076163427069952</feedId>
      <userId>154825760438254592</userId>
    </follow_challenge>
    
    
    <item>
      <title>Textual 測試實戰：Pilot、pytest-asyncio 與 Snapshot Regression</title>
      <link>https://dailypypy.org/learn/textual-testing-pilot-snapshot/</link>
      <pubDate>Thu, 27 Aug 2026 12:43:00 +0800</pubDate>
      
      <guid>https://dailypypy.org/learn/textual-testing-pilot-snapshot/</guid>
      <description>&lt;!---
1440x768
prompt: masterpiece, best quality, highres, clean anime illustration, japanese anime style, soft shading, flat color design, 1girl, black hair, green eyes, white off-shoulder shirt, black short skirt, wide shot, small figure, side profile sitting sideways on a low blank cube with legs crossed, looking over shoulder at viewer, alert mischievous smile, pastel apricot background, subtle floating translucent terminal window frames and paired comparison panels without symbols or text, neat composition, detailed eyes, cute and smart vibe, minimal background, polished illustration, no text
negative prompt: worst quality, bad eye, bad hand, extra limbs, manga, multiple views, monochrome, text, signature
dedup note: This is a testing-specific follow-up to ../python-textual/, ../textual-background-workers/, and ../textual-form-wizard/. Those posts teach widgets, layout, reactive state, workers, and form workflows; this article focuses on headless App.run_test(), Pilot keyboard/mouse interaction, pytest-asyncio configuration, deterministic terminal sizes, message draining, and SVG snapshot regression. It also differs from ../python-pytest/ and ../python-pytest-fixtures/, which cover general pytest structure rather than Textual&#39;s message loop and rendered terminal UI.
---&gt;
&lt;p&gt;





&lt;figure&gt;
    &lt;img class=&#34;my-0 rounded-md&#34; loading=&#34;lazy&#34; alt=&#34;featured&#34; src=&#34;./featured.png&#34; /&gt;

  
&lt;/figure&gt;
&lt;/p&gt;

&lt;h2 class=&#34;relative group&#34;&gt;一. 前言：手動點過，不等於下次還能用 
    &lt;div id=&#34;一-前言手動點過不等於下次還能用&#34; class=&#34;anchor&#34;&gt;&lt;/div&gt;
    
    &lt;span
        class=&#34;absolute top-0 w-6 transition-opacity opacity-0 ltr:-left-6 rtl:-right-6 not-prose group-hover:opacity-100&#34;&gt;
        &lt;a class=&#34;group-hover:text-primary-300 dark:group-hover:text-neutral-700&#34;
            style=&#34;text-decoration-line: none !important;&#34; href=&#34;#%e4%b8%80-%e5%89%8d%e8%a8%80%e6%89%8b%e5%8b%95%e9%bb%9e%e9%81%8e%e4%b8%8d%e7%ad%89%e6%96%bc%e4%b8%8b%e6%ac%a1%e9%82%84%e8%83%bd%e7%94%a8&#34; aria-label=&#34;定位點&#34;&gt;#&lt;/a&gt;
    &lt;/span&gt;        
    
&lt;/h2&gt;
&lt;p&gt;Textual 很適合快速做終端機介面。
但 App 一旦有 Input、Button、Screen、背景工作與 CSS，測試就容易停在一句：「我剛剛有按過，看起來正常。」
問題是，下一次改版可能讓快捷鍵失效、按鈕點了沒有更新狀態，或只在窄終端機把版面擠壞。
這些 bug 不一定會讓程式 crash，卻會讓使用者卡住。
這篇拍拍君要把 Textual App 放進 pytest：&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;用 &lt;code&gt;App.run_test()&lt;/code&gt; 在 headless 模式啟動 TUI&lt;/li&gt;
&lt;li&gt;用 &lt;code&gt;Pilot&lt;/code&gt; 模擬鍵盤與滑鼠&lt;/li&gt;
&lt;li&gt;用 &lt;code&gt;pytest-asyncio&lt;/code&gt; 執行非同步測試&lt;/li&gt;
&lt;li&gt;固定 terminal size，測不同版面邊界&lt;/li&gt;
&lt;li&gt;用 &lt;code&gt;pytest-textual-snapshot&lt;/code&gt; 比較 SVG 畫面
這是 &lt;a href=&#34;../python-textual/&#34;&gt;Textual 基礎篇&lt;/a&gt; 的測試專篇。
若你還在設計多步驟流程，可先看 &lt;a href=&#34;../textual-form-wizard/&#34;&gt;Textual Form Wizard&lt;/a&gt;；長任務則可搭配 &lt;a href=&#34;../textual-background-workers/&#34;&gt;Background Workers&lt;/a&gt; 一起讀。&lt;/li&gt;
&lt;/ul&gt;</description>
      <media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://dailypypy.org/learn/textual-testing-pilot-snapshot/featured.png" />
    </item>
    
  </channel>
</rss>
