From 0c5515129b1a5e1dae19fb0e621a2e2676417ec7 Mon Sep 17 00:00:00 2001 From: yusyus Date: Wed, 22 Oct 2025 22:53:49 +0300 Subject: [PATCH] Fix flaky upload_skill tests by restoring cwd in parallel scraping tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: - 2 tests in test_upload_skill.py failing intermittently in CI - Tests passed individually but failed when run after test_parallel_scraping.py - Tests failed with exit code 2 instead of 0 when running `--help` Root Cause: - test_parallel_scraping.py calls `os.chdir(tmpdir)` to create temporary test directories - These directory changes persisted across test classes - When upload_skill CLI tests ran subprocess with path 'cli/upload_skill.py', the relative path was broken because cwd was still in the temp directory - Result: subprocess couldn't find the script, returned exit code 2 Fix: - Added setUp/tearDown to all 6 test classes in test_parallel_scraping.py - setUp saves original cwd with `self.original_cwd = os.getcwd()` - tearDown restores it with `os.chdir(self.original_cwd)` - Ensures tests don't pollute working directory state for subsequent tests Impact: - All 158 tests now pass consistently - No more flaky failures in CI - Test isolation properly maintained 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- tests/test_parallel_scraping.py | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/test_parallel_scraping.py b/tests/test_parallel_scraping.py index babeba3..f8e1563 100644 --- a/tests/test_parallel_scraping.py +++ b/tests/test_parallel_scraping.py @@ -22,6 +22,14 @@ from doc_scraper import DocToSkillConverter class TestParallelScrapingConfiguration(unittest.TestCase): """Test parallel scraping configuration and initialization""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_single_worker_default(self): """Test default is single-worker mode""" config = { @@ -71,6 +79,14 @@ class TestParallelScrapingConfiguration(unittest.TestCase): class TestUnlimitedMode(unittest.TestCase): """Test unlimited scraping mode""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_unlimited_with_none(self): """Test max_pages: None enables unlimited mode""" config = { @@ -118,6 +134,14 @@ class TestUnlimitedMode(unittest.TestCase): class TestRateLimiting(unittest.TestCase): """Test rate limiting configuration""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_rate_limit_from_config(self): """Test rate_limit is read from config""" config = { @@ -163,6 +187,14 @@ class TestRateLimiting(unittest.TestCase): class TestThreadSafety(unittest.TestCase): """Test thread-safety fixes""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_lock_protects_visited_urls(self): """Test visited_urls operations are protected by lock""" config = { @@ -201,6 +233,14 @@ class TestThreadSafety(unittest.TestCase): class TestScrapingModes(unittest.TestCase): """Test different scraping mode combinations""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_single_threaded_limited(self): """Test traditional single-threaded limited mode""" config = { @@ -272,6 +312,14 @@ class TestScrapingModes(unittest.TestCase): class TestDryRunWithNewFeatures(unittest.TestCase): """Test dry-run mode works with new features""" + def setUp(self): + """Save original working directory""" + self.original_cwd = os.getcwd() + + def tearDown(self): + """Restore original working directory""" + os.chdir(self.original_cwd) + def test_dry_run_with_parallel(self): """Test dry-run with parallel workers""" config = {