private TestCase TryCreateVsTestCase(PytestTest test, string projectHome) { try { TestCase tc = test.ToVsTestCase(projectHome); return(tc); } catch (Exception ex) { Error(ex.Message); } return(null); }
/// <summary> /// Parses the relative source and line number from a PytestTest discovery result /// Example Test "source": ".\\test_user_marks.py:17", /// returns (test_user_marks.py, 17) /// </summary> /// <param name="test"></param> /// <returns></returns> public static (string, int) ParseSourceAndLine(this PytestTest test) { int line = 0; var sourceAndLineNum = test.Source.Replace(".\\", ""); var sourceParts = sourceAndLineNum.Split(':'); if (sourceParts.Length != 2 || !Int32.TryParse(sourceParts[1], out line)) { throw new FormatException(Strings.PytestInvalidTestSource.FormatUI(test.ToString())); } return(sourceParts[0], line); }
public static TestCase ToVsTestCase( this PytestTest test, string source, int line, Dictionary <string, PytestParent> parentMap, string projectHome ) { if (parentMap == null) { throw new ArgumentException(nameof(parentMap)); } if (String.IsNullOrWhiteSpace(source)) { throw new ArgumentException(nameof(source) + " " + test.ToString()); } if (String.IsNullOrWhiteSpace(projectHome)) { throw new ArgumentException(nameof(projectHome)); } if (String.IsNullOrWhiteSpace(test.Name) || String.IsNullOrWhiteSpace(test.Id)) { throw new FormatException(test.ToString()); } var pytestId = CreateProperCasedPytestId(source, projectHome, test.Id); var fullyQualifiedName = CreateFullyQualifiedTestNameFromId(source, pytestId); var tc = new TestCase(fullyQualifiedName, PythonConstants.PytestExecutorUri, source) { DisplayName = test.Name, LineNumber = line, CodeFilePath = source }; tc.SetPropertyValue(Constants.PytestIdProperty, pytestId); foreach (var marker in test.Markers.MaybeEnumerate()) { tc.Traits.Add(new Trait(marker.ToString(), String.Empty)); } return(tc); }
/// <summary> /// Creates a classname that matches the junit testresult generated one so that we can match testresults with testcases /// Note if a function doesn't have a class, its classname appears to be the filename without an extension /// </summary> /// <param name="t"></param> /// <param name="parentMap"></param> /// <returns></returns> internal static string CreateXmlClassName(PytestTest t, Dictionary <string, PytestParent> parentMap) { var parentList = new List <string>(); var currId = t.Parentid; while (parentMap.TryGetValue(currId, out PytestParent parent)) { // class names for functions dont append the direct parent if (String.Compare(parent.Kind, "function", StringComparison.OrdinalIgnoreCase) != 0) { parentList.Add(Path.GetFileNameWithoutExtension(parent.Name)); } currId = parent.Parentid; } parentList.Reverse(); var xmlClassName = String.Join(".", parentList); return(xmlClassName); }
public static TestCase ToVsTestCase( this PytestTest test, string projectHome ) { if (String.IsNullOrWhiteSpace(projectHome)) { throw new ArgumentException(nameof(projectHome)); } if (String.IsNullOrWhiteSpace(test.Name) || String.IsNullOrWhiteSpace(test.Id)) { throw new FormatException(test.ToString()); } (string parsedSource, int line) = test.ParseSourceAndLine(); // Note: we use _settings.ProjectHome and not result.root since it is being lowercased var sourceFullPath = Path.IsPathRooted(parsedSource) ? parsedSource : PathUtils.GetAbsoluteFilePath(projectHome, parsedSource); if (String.IsNullOrWhiteSpace(sourceFullPath)) { throw new FormatException(nameof(sourceFullPath) + " " + test.ToString()); } var pytestId = CreateProperCasedPytestId(sourceFullPath, projectHome, test.Id); var fullyQualifiedName = CreateFullyQualifiedTestNameFromId(sourceFullPath, pytestId); var tc = new TestCase(fullyQualifiedName, PythonConstants.PytestExecutorUri, sourceFullPath) { DisplayName = FixupParameterSets(test.Name), LineNumber = line, CodeFilePath = sourceFullPath }; tc.SetPropertyValue(Constants.PytestIdProperty, pytestId); foreach (var marker in test.Markers.MaybeEnumerate()) { tc.Traits.Add(new Trait(marker.ToString(), String.Empty)); } return(tc); }