anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

Fix test collection and execution errors on Windows (geteuid, FileStore skip, bedrock tempfile lock)

Open prasad2512 opened this issue 1 month ago • 2 comments

Summary

Running the test suite on Windows (or collecting tests with pytest) encounters multiple crashes and collection failures due to POSIX assumptions in tests:

  1. AttributeError: module 'os' has no attribute 'geteuid' during test collection: In tests/lib/tools/test_file_store.py:207, 317 and tests/lib/tools/memory_sync/test_delete_discipline.py:168:

    @pytest.mark.skipif(os.geteuid() == 0, reason="permission checks do not bind root")
    

    Because os.geteuid does not exist on Windows, evaluating it in the decorator during pytest module import crashes collection immediately:

    AttributeError: module 'os' has no attribute 'geteuid'
    

    This prevents pytest from discovering or running any subsequent tests.

  2. Unskipped POSIX-only FileStore suites: FileStore explicitly requires _O_NOFOLLOW != 0 (_platform_supported()) and raises RuntimeError("FileStore requires O_NOFOLLOW support on this platform") on non-POSIX platforms. test_file_store.py carries:

    pytestmark = pytest.mark.skipif(os.name != "posix", reason="FileStore refuses non-POSIX platforms")
    

    However, tests/lib/tools/memory_sync/test_memory_sync.py and tests/lib/tools/memory_sync/test_delete_discipline.py were missing this file-level marker, causing 38 test failures on Windows.

  3. tempfile.NamedTemporaryFile file-locking contention in mock_aws_config: In tests/lib/test_bedrock.py:65:

    with tempfile.NamedTemporaryFile(mode="w+", delete=True) as temp_file:
        ...
        monkeypatch.setenv("AWS_CONFIG_FILE", str(temp_file.name))
        yield
    

    On Windows, an open NamedTemporaryFile(delete=True) cannot be opened by a second handle (boto3.Session). boto3 encounters a PermissionError [Errno 13], which botocore catches and translates to botocore.exceptions.ProfileNotFound, causing 4 test failures:

    • test_region_infer_from_profile
    • test_region_infer_from_specified_profile[default profile]
    • test_region_infer_from_specified_profile[custom profile]
    • test_region_infer_from_aws_profile_argument[profiles0]
  4. Missing @needs_symlinks marker on symlink tests: In tests/lib/tools/test_agent_toolset.py, three tests (test_read_through_symlink_escape_is_rejected, test_glob_post_filters_symlink_escape, and test_grep_skips_symlinked_files) create symlinks without carrying the @needs_symlinks marker, failing on Windows machines where symlink privileges are restricted (OSError: [WinError 1314]).

Expected Behavior

  • Guard os.geteuid() with os.name != "posix" so non-POSIX platforms skip cleanly without collection crashes.
  • Mark memory sync suites to skip on non-POSIX platforms matching test_file_store.py.
  • Use pytest's tmp_path fixture for mock_aws_config in test_bedrock.py to avoid Windows file-locking contention.
  • Apply @needs_symlinks to the remaining symlink tests in test_agent_toolset.py.

prasad2512 avatar Oct 19 '26 17:10 prasad2512

I'd like to take this. Plan, matching your four items: guard the os.geteuid() skipif decorators with os.name == "posix" (test_file_store.py ×2, test_delete_discipline.py), add the missing non-POSIX pytestmark to test_memory_sync.py and test_delete_discipline.py, switch the mock_aws_config fixture to a locked-file-safe pattern (delete=False + explicit unlink, or TemporaryDirectory), and add the @needs_symlinks marker to the three unmarked symlink tests in test_agent_toolset.py. I'll verify on a native Windows machine (this one): clean collection, the 38 + 4 failures gone, symlink tests skip where privileges are restricted.

Dopetaiga avatar Oct 25 '26 08:10 Dopetaiga

Hi @Dopetaiga, as linked in the issue description, PR #2028 addressing this was already submitted by me, verified across Linux/Pytest, and officially approved by @chrikrah. It is currently awaiting maintainer merge from @dtmeadows-ant.

prasad2512 avatar Oct 25 '26 09:10 prasad2512