77from pathlib import Path
88from typing import Any , Dict , List , Tuple , Callable , Optional
99
10- import capturer
1110import pytest
1211from _pytest ._code import ExceptionInfo
1312from _pytest ._code .code import ReprEntry , ReprFileLocation
1716from mypy .main import process_options
1817from pytest_mypy import utils
1918from pytest_mypy .collect import File , YamlTestFile
20- from pytest_mypy .utils import TypecheckAssertionError , assert_string_arrays_equal , fname_to_module
19+ from pytest_mypy .utils import (
20+ TypecheckAssertionError ,
21+ capture_std_streams ,
22+ assert_string_arrays_equal ,
23+ fname_to_module ,
24+ )
2125
2226
2327class TraceLastReprEntry (ReprEntry ):
@@ -163,6 +167,9 @@ def typecheck_in_new_subprocess(self, execution_path: Path, mypy_cmd_options: Li
163167
164168 # add current directory to path
165169 self .environment_variables ['PYTHONPATH' ] = str (execution_path )
170+ # Windows requires this to be set, otherwise the interpreter crashes
171+ if 'SYSTEMROOT' in os .environ :
172+ self .environment_variables ['SYSTEMROOT' ] = os .environ ['SYSTEMROOT' ]
166173 completed = subprocess .run ([mypy_executable , * mypy_cmd_options ],
167174 stdout = subprocess .PIPE , stderr = subprocess .PIPE ,
168175 cwd = os .getcwd (),
@@ -180,12 +187,10 @@ def typecheck_in_same_process(self, execution_path: Path, mypy_cmd_options: List
180187 # add current directory to path
181188 sys .path .insert (0 , str (execution_path ))
182189
183- with capturer . CaptureOutput ( merged = False ) as captured_std_streams :
190+ with capture_std_streams ( ) as ( stdout , stderr ) :
184191 return_code = run_mypy_typechecking (mypy_cmd_options )
185192
186- stdout = captured_std_streams .stdout .get_text ()
187- stderr = captured_std_streams .stderr .get_text ()
188- return return_code , (stdout , stderr )
193+ return return_code , (stdout .getvalue (), stderr .getvalue ())
189194
190195 def execute_extension_hook (self ) -> None :
191196 extension_hook_fqname = self .config .option .mypy_extension_hook
0 commit comments