From b5df2126b9741f9b3c6781c09e29f303a5bb787c Mon Sep 17 00:00:00 2001 From: Hongming Wang Date: Thu, 30 Apr 2026 01:47:27 -0700 Subject: [PATCH] fix(test): convert migration-collision tests from pytest to unittest (#2341) CI failure: the Ops scripts (unittest) job runs `python -m unittest discover` which doesn't have pytest installed. test_check_migration_ collisions.py imported pytest unconditionally, failing module import: ImportError: Failed to import test module: test_check_migration_collisions Traceback (most recent call last): File ".../test_check_migration_collisions.py", line 12, in import pytest ModuleNotFoundError: No module named 'pytest' The tests use no pytest-specific features (just bare assert + plain class). Sibling test_sweep_cf_decide.py in the same dir already uses unittest.TestCase. Convert this one to match: drop the pytest import, make TestMigrationFileRe inherit from unittest.TestCase. unittest.TestLoader.discover() requires TestCase subclasses for auto-discovery, so the fix is two lines (drop import, add base). Bare assert statements work fine inside TestCase methods. Verified: `python3 -m unittest scripts.ops.test_check_migration_collisions -v` runs all 9 tests, all pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- scripts/ops/test_check_migration_collisions.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/ops/test_check_migration_collisions.py b/scripts/ops/test_check_migration_collisions.py index b500a7b3..4eedb75f 100644 --- a/scripts/ops/test_check_migration_collisions.py +++ b/scripts/ops/test_check_migration_collisions.py @@ -4,13 +4,14 @@ classifier + the diff/base-set logic that runs without git. The end-to-end git diff + gh pr list path is exercised manually (running the workflow against test PRs). These tests pin the pure-logic surface so a regression in migration-name parsing fails immediately at PR time. + +Run locally: ``python3 -m unittest scripts/ops/test_check_migration_collisions.py -v`` """ import importlib.util +import unittest from pathlib import Path -import pytest - # Load the script as a module without invoking main(). We import the # regex + helpers directly so we can test them without setting up git. SCRIPT_PATH = Path(__file__).parent / "check_migration_collisions.py" @@ -19,7 +20,7 @@ ccm = importlib.util.module_from_spec(spec) spec.loader.exec_module(ccm) -class TestMigrationFileRe: +class TestMigrationFileRe(unittest.TestCase): """The regex classifier — the load-bearing piece of the detector.""" def test_matches_standard_three_digit_prefix(self):