Create

Sign in to ReadmeX

or

How we handle your data: Privacy Policy

ReadmeX

Your AI reading companion

What would you like to catch up on?

Pick a briefing, or ask your own question.

Your community and people briefings stay personal to you.

Story

A Codex Tutorial for Writing CLI Regression Tests

AI summary

This AI-assisted tutorial shows how to use Codex to create five regression tests for a Python command-line script, covering CSV contents, empty input, missing input, invalid arguments, and suffix case sensitivity. The author reports that the correct script passed all five tests, while an intentionally faulty copy produced three failures, with the original script and tests left unchanged.

In-depth insight

The example demonstrates a practical way to ask Codex for repeatable tests that check both successful behavior, error handling, and file side effects rather than only happy paths.

上一篇,我们把默认后缀少一个点的故障复现出来,只修了一行。接下来再改脚本时,总不能靠记忆把这些命令重新敲一遍。

这一篇把约定写成能反复执行的测试:有数据时检查CSV内容,没有数据时检查表头,输入不合法时检查退出码和旧结果是否保留。最后把同一套测试交给故障版,看看它们能不能报出问题。

示例已编写并验证。创作说明:AI 辅助创作。

本篇目标与前置条件

准备第08篇修好后的file_list.py,保留.txt默认后缀和--suffix参数。新建一个独立练习目录,把脚本副本放进去;不要直接用真实资料目录测试。

本次实际环境为Windows、已有Python 3.10.6,使用标准库unittest、tempfile和subprocess,没有安装测试依赖。这是环境记录,不是建议专门安装这个旧版本。下面命令里的python应替换为你确认过的解释器;本次实际执行使用了该解释器的绝对路径。

#Codex#OpenAI#Python

Original · 7 min readRead the original
Group chat

No comments yet. Start the conversation.