private void SetupWorkspace(IPythonWorkspaceContext workspace) { if (workspace == null) { return; } TestFrameworkType testFrameworkType = GetTestFramework(workspace); if (testFrameworkType != TestFrameworkType.None) { var projInfo = new ProjectInfo(workspace); _projectMap[projInfo.ProjectHome] = projInfo; var oldWatcher = _testFilesUpdateWatcher; _testFilesUpdateWatcher = new TestFilesUpdateWatcher(); _testFilesUpdateWatcher.FileChangedEvent += OnWorkspaceFileChanged; _testFilesUpdateWatcher.AddDirectoryWatch(workspace.Location); oldWatcher?.Dispose(); Regex testFileFilterRegex = new Regex(@".*\.(py|txt)", RegexOptions.Compiled | RegexOptions.IgnoreCase); Predicate <string> testFileFilter = (x) => testFileFilterRegex.IsMatch(x); foreach (var file in _workspaceContextProvider.Workspace.EnumerateUserFiles(testFileFilter)) { projInfo.AddTestContainer(this, file); } workspace.ActiveInterpreterChanged -= OnActiveInterpreterChanged; workspace.ActiveInterpreterChanged += OnActiveInterpreterChanged; _packageManagerEventSink.WatchPackageManagers(workspace.CurrentFactory); } }
public PythonProjectSettings(string projectName, string projectHome, string workingDir, string interpreter, string pathEnv, bool nativeDebugging, bool isWorkspace, bool useLegacyDebugger, string testFramework, string unitTestPattern, string unitTestRootDir, string discoveryWaitTimeInSeconds) { ProjectName = projectName; ProjectHome = projectHome; WorkingDirectory = workingDir; InterpreterPath = interpreter; PathEnv = pathEnv; EnableNativeCodeDebugging = nativeDebugging; SearchPath = new List <string>(); Environment = new Dictionary <string, string>(); // Mapping of full file path to full file path which was assigned to the TestContainer. // The pytest adapter discovery is returning lowercase paths and Test Explorer needs TestCase sources and TestContainer sources // to match or else tests wont be removed when you unload a project. TestContainerSources = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); IsWorkspace = isWorkspace; UseLegacyDebugger = useLegacyDebugger; TestFramework = TestFrameworkType.None; Enum.TryParse <TestFrameworkType>(testFramework, ignoreCase: true, out TestFramework); UnitTestPattern = string.IsNullOrEmpty(unitTestPattern) ? PythonConstants.DefaultUnitTestPattern : unitTestPattern; UnitTestRootDir = string.IsNullOrEmpty(unitTestRootDir) ? PythonConstants.DefaultUnitTestRootDirectory : unitTestRootDir; DiscoveryWaitTimeInSeconds = Int32.TryParse(discoveryWaitTimeInSeconds, out int parsedWaitTime) ? parsedWaitTime : PythonConstants.DiscoveryTimeoutInSeconds; DiscoveryWaitTimeInSeconds = DiscoveryWaitTimeInSeconds > 0 ? DiscoveryWaitTimeInSeconds : PythonConstants.DiscoveryTimeoutInSeconds; }
/// <summary> /// /// </summary> /// <param name="vsProject"></param> /// <returns>True if loaded any files</returns> private bool LoadProject(IVsProject vsProject) { // check for python projects var pyProj = PythonProject.FromObject(vsProject); if (pyProj == null) { return(false); } // always register for project property changes pyProj.ProjectPropertyChanged -= OnTestPropertiesChanged; pyProj.ProjectPropertyChanged += OnTestPropertiesChanged; TestFrameworkType testFrameworkType = GetTestFramework(pyProj); if (testFrameworkType == TestFrameworkType.None) { return(false); } pyProj.ActiveInterpreterChanged -= OnActiveInterpreterChanged; pyProj.ActiveInterpreterChanged += OnActiveInterpreterChanged; _packageManagerEventSink.WatchPackageManagers(pyProj.GetInterpreterFactory()); var projInfo = new ProjectInfo(pyProj); var files = FilteredTestOrSettingsFiles(vsProject); UpdateContainersAndListeners(files, projInfo, isAdd: true); _projectMap[projInfo.ProjectHome] = projInfo; return(files.Any()); }
/// <summary> /// Create a test framework specific Test Discoverer /// </summary> /// <param name="frameworkType"></param> protected PythonTestDiscoverer(TestFrameworkType frameworkType) { _frameworkType = frameworkType; }
public static Dictionary <string, PythonProjectSettings> GetSourceToProjSettings(IRunSettings settings, TestFrameworkType filterType) { var doc = Read(settings.SettingsXml); XPathNodeIterator nodes = doc.CreateNavigator().Select("/RunSettings/Python/TestCases/Project"); var res = new Dictionary <string, PythonProjectSettings>(StringComparer.OrdinalIgnoreCase); foreach (XPathNavigator project in nodes) { PythonProjectSettings projSettings = new PythonProjectSettings( project.GetAttribute("name", ""), project.GetAttribute("home", ""), project.GetAttribute("workingDir", ""), project.GetAttribute("interpreter", ""), project.GetAttribute("pathEnv", ""), project.GetAttribute("nativeDebugging", "").IsTrue(), project.GetAttribute("isWorkspace", "").IsTrue(), project.GetAttribute("useLegacyDebugger", "").IsTrue(), project.GetAttribute("testFramework", ""), project.GetAttribute("unitTestPattern", ""), project.GetAttribute("unitTestRootDir", ""), project.GetAttribute("discoveryWaitTime", "") ); if (projSettings.TestFramework != filterType) { continue; } foreach (XPathNavigator environment in project.Select("Environment/Variable")) { projSettings.Environment[environment.GetAttribute("name", "")] = environment.GetAttribute("value", ""); } string djangoSettings = project.GetAttribute("djangoSettingsModule", ""); if (!String.IsNullOrWhiteSpace(djangoSettings)) { projSettings.Environment["DJANGO_SETTINGS_MODULE"] = djangoSettings; } foreach (XPathNavigator searchPath in project.Select("SearchPaths/Search")) { projSettings.SearchPath.Add(searchPath.GetAttribute("value", "")); } foreach (XPathNavigator test in project.Select("Test")) { string testFile = test.GetAttribute("file", ""); projSettings.TestContainerSources.Add(testFile, testFile); res[testFile] = projSettings; } } return(res); }