@@ -583,8 +583,11 @@ def sdist_built_at_runtime_with_build(my_run_subprocess) -> Path:
583583 # Create a temporary directory
584584 import tempfile
585585 import typing as t
586+ import os
586587
587- temp_dir : str = tempfile .mkdtemp ()
588+ # Make directory unique for pytest-xdist parallel execution
589+ worker_id = os .environ .get ("PYTEST_XDIST_WORKER" , "master" )
590+ temp_dir : str = tempfile .mkdtemp (suffix = f"-{ worker_id } " )
588591
589592 OUT_DIR = Path (temp_dir ) / "unit-test-sdist_built_at_runtime_with_build"
590593 # Get distro_path: ie '/site-packages/cookiecutter_python'
@@ -605,15 +608,67 @@ def sdist_built_at_runtime_with_build(my_run_subprocess) -> Path:
605608 str (OUT_DIR ),
606609 str (project_path ),
607610 ]
608- result = my_run_subprocess (* COMMAND_LINE_ARGS , check = False )
611+
612+ # Add isolation to prevent cross-worker conflicts
613+ env = os .environ .copy ()
614+ env ["BUILD_BACKEND_ISOLATION" ] = "true"
615+ env ["SETUPTOOLS_SCM_DEBUG" ] = "1" if worker_id != "master" else "0"
616+
617+ print (f"\n [Worker { worker_id } ] Building with command: { ' ' .join (COMMAND_LINE_ARGS )} " )
618+ print (f"[Worker { worker_id } ] Output directory: { OUT_DIR } " )
619+ print (f"[Worker { worker_id } ] Project path: { project_path } " )
620+ print (f"[Worker { worker_id } ] Python executable: { PYTHON } " )
621+ print (f"[Worker { worker_id } ] Current working directory: { os .getcwd ()} " )
622+
623+ # Check for potential lock files that could cause conflicts
624+ lock_files = [
625+ project_path / "poetry.lock" ,
626+ project_path / ".build-lock" ,
627+ project_path / "pyproject.toml.lock"
628+ ]
629+ for lock_file in lock_files :
630+ if lock_file .exists ():
631+ print (f"[Worker { worker_id } ] Lock file exists: { lock_file } " )
632+
633+ result = my_run_subprocess (* COMMAND_LINE_ARGS , check = False , env = env )
609634
610635 print ()
611- print ("==========" )
612- print (result .stdout )
613- print ("==========" )
614- print (result .stderr )
615- print ("==========" )
616- assert result .exit_code == 0 , f"Expected exit code 0, got { result .exit_code } "
636+ print ("=" * 60 )
637+ print (f"[Worker { worker_id } ] BUILD RESULT - Exit code: { result .exit_code } " )
638+ print ("=" * 60 )
639+ print ("STDOUT:" )
640+ stdout_content = result .stdout if result .stdout else "(empty)"
641+ print (repr (stdout_content )) # Use repr to see hidden characters
642+ print (stdout_content )
643+ print ("=" * 60 )
644+ print ("STDERR:" )
645+ stderr_content = result .stderr if result .stderr else "(empty)"
646+ print (repr (stderr_content )) # Use repr to see hidden characters
647+ print (stderr_content )
648+ print ("=" * 60 )
649+
650+ if result .exit_code != 0 :
651+ print (f"[Worker { worker_id } ] BUILD FAILED!" )
652+ print (f"Command: { ' ' .join (COMMAND_LINE_ARGS )} " )
653+ print (f"Working directory: { project_path } " )
654+ print (f"Output directory exists: { OUT_DIR .exists ()} " )
655+ if OUT_DIR .exists ():
656+ print (f"Output directory contents: { list (OUT_DIR .iterdir ()) if OUT_DIR .is_dir () else 'Not a directory' } " )
657+
658+ # Additional debugging for CI environment
659+ print (f"Environment variables of interest:" )
660+ debug_env_vars = ["PYTHONPATH" , "PATH" , "HOME" , "BUILD_BACKEND_ISOLATION" , "SETUPTOOLS_SCM_DEBUG" ]
661+ for var in debug_env_vars :
662+ print (f" { var } : { env .get (var , 'NOT SET' )} " )
663+
664+ assert result .exit_code == 0 , (
665+ f"[Worker { worker_id } ] Build failed with exit code { result .exit_code } \n "
666+ f"Command: { ' ' .join (COMMAND_LINE_ARGS )} \n "
667+ f"Working directory: { project_path } \n "
668+ f"Environment: PYTEST_XDIST_WORKER={ worker_id } \n "
669+ f"STDOUT: { repr (result .stdout )} \n "
670+ f"STDERR: { repr (result .stderr )} "
671+ )
617672
618673 import re
619674
0 commit comments