@@ -11,16 +11,16 @@ def test_virtualenv_py_race_condition_find_spec():
1111 # Create a temporary file with partial _virtualenv.py content (simulating race condition)
1212 with tempfile .TemporaryDirectory () as tmpdir :
1313 venv_file = Path (tmpdir ) / "_virtualenv_test.py"
14-
14+
1515 # Write a partial version of _virtualenv.py that has _Finder but not _DISTUTILS_PATCH
1616 # This simulates the state during a race condition where the file is being rewritten
1717 partial_content = dedent ("""
1818 import sys
19-
19+
2020 class _Finder:
2121 fullname = None
2222 lock = []
23-
23+
2424 def find_spec(self, fullname, path, target=None):
2525 # This should handle the NameError gracefully
2626 try:
@@ -30,7 +30,7 @@ def find_spec(self, fullname, path, target=None):
3030 if fullname in distutils_patch and self.fullname is None:
3131 return None
3232 return None
33-
33+
3434 @staticmethod
3535 def exec_module(old, module):
3636 old(module)
@@ -40,7 +40,7 @@ def exec_module(old, module):
4040 return
4141 if module.__name__ in distutils_patch:
4242 pass # Would call patch_dist(module)
43-
43+
4444 @staticmethod
4545 def load_module(old, name):
4646 module = old(name)
@@ -51,38 +51,38 @@ def load_module(old, name):
5151 if module.__name__ in distutils_patch:
5252 pass # Would call patch_dist(module)
5353 return module
54-
54+
5555 finder = _Finder()
5656 """ )
57-
57+
5858 venv_file .write_text (partial_content , encoding = "utf-8" )
59-
59+
6060 # Add the directory to sys.path temporarily
6161 sys .path .insert (0 , tmpdir )
6262 try :
6363 # Import the module
64- import _virtualenv_test # noqa: F401
65-
64+ import _virtualenv_test
65+
6666 # Get the finder instance
6767 finder = _virtualenv_test .finder
68-
68+
6969 # Try to call find_spec - this should not raise NameError
7070 result = finder .find_spec ("distutils.dist" , None )
7171 assert result is None , "find_spec should return None when _DISTUTILS_PATCH is not defined"
72-
72+
7373 # Create a mock module object
7474 class MockModule :
7575 __name__ = "distutils.dist"
76-
76+
7777 # Try to call exec_module - this should not raise NameError
7878 mock_old_exec = lambda x : None # noqa: E731
7979 finder .exec_module (mock_old_exec , MockModule ())
80-
80+
8181 # Try to call load_module - this should not raise NameError
8282 mock_old_load = lambda name : MockModule () # noqa: E731
8383 result = finder .load_module (mock_old_load , "distutils.dist" )
8484 assert result .__name__ == "distutils.dist"
85-
85+
8686 finally :
8787 # Clean up
8888 sys .path .remove (tmpdir )
0 commit comments