Fix test collection and execution errors on Windows (geteuid, FileStore skip, bedrock tempfile lock)
Summary
Running the test suite on Windows (or collecting tests with pytest) encounters multiple crashes and collection failures due to POSIX assumptions in tests:
-
AttributeError: module 'os' has no attribute 'geteuid'during test collection: Intests/lib/tools/test_file_store.py:207, 317andtests/lib/tools/memory_sync/test_delete_discipline.py:168:@pytest.mark.skipif(os.geteuid() == 0, reason="permission checks do not bind root")Because
os.geteuiddoes 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.
-
Unskipped POSIX-only
FileStoresuites:FileStoreexplicitly requires_O_NOFOLLOW != 0(_platform_supported()) and raisesRuntimeError("FileStore requires O_NOFOLLOW support on this platform")on non-POSIX platforms.test_file_store.pycarries:pytestmark = pytest.mark.skipif(os.name != "posix", reason="FileStore refuses non-POSIX platforms")However,
tests/lib/tools/memory_sync/test_memory_sync.pyandtests/lib/tools/memory_sync/test_delete_discipline.pywere missing this file-level marker, causing 38 test failures on Windows. -
tempfile.NamedTemporaryFilefile-locking contention inmock_aws_config: Intests/lib/test_bedrock.py:65:with tempfile.NamedTemporaryFile(mode="w+", delete=True) as temp_file: ... monkeypatch.setenv("AWS_CONFIG_FILE", str(temp_file.name)) yieldOn Windows, an open
NamedTemporaryFile(delete=True)cannot be opened by a second handle (boto3.Session).boto3encounters aPermissionError[Errno 13], which botocore catches and translates tobotocore.exceptions.ProfileNotFound, causing 4 test failures:test_region_infer_from_profiletest_region_infer_from_specified_profile[default profile]test_region_infer_from_specified_profile[custom profile]test_region_infer_from_aws_profile_argument[profiles0]
-
Missing
@needs_symlinksmarker on symlink tests: Intests/lib/tools/test_agent_toolset.py, three tests (test_read_through_symlink_escape_is_rejected,test_glob_post_filters_symlink_escape, andtest_grep_skips_symlinked_files) create symlinks without carrying the@needs_symlinksmarker, failing on Windows machines where symlink privileges are restricted (OSError: [WinError 1314]).
Expected Behavior
- Guard
os.geteuid()withos.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_pathfixture formock_aws_configintest_bedrock.pyto avoid Windows file-locking contention. - Apply
@needs_symlinksto the remaining symlink tests intest_agent_toolset.py.
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.
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.