internal static void DetachFromSillyManagedProcess(VisualStudioProxy app, PythonDebugMode debugMode) { var dte = app?.GetDTE(); if (dte != null && debugMode != PythonDebugMode.None) { dte.Debugger.DetachAll(); } }
public TestRunner( IFrameworkHandle frameworkHandle, IRunContext runContext, IEnumerable <TestCase> tests, string codeCoverageFile, PythonProjectSettings settings, VisualStudioProxy app, ManualResetEvent cancelRequested) { _frameworkHandle = frameworkHandle; _context = runContext; _tests = tests.ToArray(); _codeCoverageFile = codeCoverageFile; _settings = settings; _app = app; _cancelRequested = cancelRequested; _dryRun = IsDryRun(runContext.RunSettings); _showConsole = ShouldShowConsole(runContext.RunSettings); _env = new Dictionary <string, string>(); _debugMode = PythonDebugMode.None; if (runContext.IsBeingDebugged && _app != null) { _debugMode = settings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly; } _searchPaths = GetSearchPaths(tests, settings); if (_debugMode == PythonDebugMode.PythonOnly) { if (_settings.UseLegacyDebugger) { var secretBuffer = new byte[24]; RandomNumberGenerator.Create().GetNonZeroBytes(secretBuffer); _debugSecret = Convert.ToBase64String(secretBuffer) .Replace('+', '-') .Replace('/', '_') .TrimEnd('='); } else { _debugSecret = ""; } SocketUtils.GetRandomPortListener(IPAddress.Loopback, out _debugPort).Stop(); } _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); _socket.Bind(new IPEndPoint(IPAddress.Loopback, 0)); _socket.Listen(0); _socket.BeginAccept(AcceptConnection, _socket); }
internal static void AttachDebugger(VisualStudioProxy app, ProcessOutput proc, PythonDebugMode debugMode, string debugSecret, int debugPort) { if (debugMode == PythonDebugMode.PythonOnly) { string qualifierUri = string.Format("tcp://{0}@localhost:{1}", debugSecret, debugPort); while (!app.AttachToProcess(proc, PythonRemoteDebugPortSupplierUnsecuredId, qualifierUri)) { if (proc.Wait(TimeSpan.FromMilliseconds(500))) { break; } } } else if (debugMode == PythonDebugMode.PythonAndNative) { var engines = new[] { PythonDebugEngineGuid, NativeDebugEngineGuid }; while (!app.AttachToProcess(proc, engines)) { if (proc.Wait(TimeSpan.FromMilliseconds(500))) { break; } } } }
internal static void GetDebugSettings(VisualStudioProxy app, IRunContext runContext, PythonProjectSettings projectSettings, out PythonDebugMode debugMode, out string debugSecret, out int debugPort) { debugMode = PythonDebugMode.None; debugSecret = ""; debugPort = 0; if (runContext.IsBeingDebugged && app != null) { debugMode = projectSettings.EnableNativeCodeDebugging ? PythonDebugMode.PythonAndNative : PythonDebugMode.PythonOnly; } if (debugMode == PythonDebugMode.PythonOnly) { if (projectSettings.UseLegacyDebugger) { var secretBuffer = new byte[24]; RandomNumberGenerator.Create().GetNonZeroBytes(secretBuffer); debugSecret = Convert.ToBase64String(secretBuffer) .Replace('+', '-') .Replace('/', '_') .TrimEnd('='); } SocketUtils.GetRandomPortListener(IPAddress.Loopback, out debugPort).Stop(); } }
public PythonTestCase(PythonProjectSettings settings, TestCase testCase, PythonDebugMode debugMode) { Settings = settings; TestCase = testCase; TestAnalyzer.ParseFullyQualifiedTestName( testCase.FullyQualifiedName, out TestFile, out TestClass, out TestMethod ); TestFilePath = CommonUtils.GetAbsoluteFilePath(Settings.ProjectHome, TestFile); ModulePath = ModulePath.FromFullPath(TestFilePath); WorkingDirectory = Settings.WorkingDir; var paths = settings.SearchPath.ToList(); paths.Insert(0, ModulePath.LibraryPath); paths.Insert(0, WorkingDirectory); if (debugMode == PythonDebugMode.PythonOnly) { paths.Insert(0, PtvsdSearchPath); } SearchPaths = string.Join( ";", paths.Where(Directory.Exists).Distinct(StringComparer.OrdinalIgnoreCase) ); var arguments = new List<string> { TestLauncherPath, "-m", ModulePath.ModuleName, "-t", string.Format("{0}.{1}", TestClass, TestMethod) }; if (debugMode == PythonDebugMode.PythonOnly) { var secretBuffer = new byte[24]; RandomNumberGenerator.Create().GetNonZeroBytes(secretBuffer); DebugSecret = Convert.ToBase64String(secretBuffer) .Replace('+', '-') .Replace('/', '_') .TrimEnd('='); DebugPort = GetFreePort(); arguments.AddRange(new[] { "-s", DebugSecret, "-p", DebugPort.ToString() }); } else if (debugMode == PythonDebugMode.PythonAndNative) { arguments.Add("-x"); } Arguments = arguments; Environment = new Dictionary<string, string>(); if (!string.IsNullOrEmpty(settings.DjangoSettingsModule)) { Environment["DJANGO_SETTINGS_MODULE"] = settings.DjangoSettingsModule; } foreach (var envVar in settings.Environment) { Environment[envVar.Key] = envVar.Value; } }