public void CreatePytestId_GlobalFuncRelative()
 {
     Assert.AreEqual(
         ".\\tests\\unit\\test_statistics.py::test_key_creation",
         JunitXmlTestResultParser.CreatePytestId("tests\\unit\\test_statistics.py", "tests.unit.test_statistics", "test_key_creation")
         );
 }
 public void CreatePytestId_ClassFuncWithRelativeFilename()
 {
     Assert.AreEqual(
         ".\\package1\\packageA\\test1.py::Test_test1::test_A",
         JunitXmlTestResultParser.CreatePytestId("package1\\packageA\\test1.py", "package1.packageA.test1.Test_test1", "test_A")
         );
 }
 public void CreatePytestId_FuncInsideClass()
 {
     Assert.AreEqual(
         ".\\test2.py::Test_test2::test_A",
         JunitXmlTestResultParser.CreatePytestId("test2.py", "test2.Test_test2", "test_A")
         );
 }
 public void CreatePytestId_GlobalFunc()
 {
     Assert.AreEqual(
         ".\\test_sample.py::test_answer",
         JunitXmlTestResultParser.CreatePytestId("test_sample.py", "test_sample", "test_answer")
         );
 }
示例#5
0
        private void Parse(
            XPathDocument doc,
            Dictionary <string, TestResult> pytestIdToResultsMap,
            IFrameworkHandle frameworkHandle
            )
        {
            var xmlTestResultNodes = doc.CreateNavigator().SelectDescendants("testcase", "", false);

            foreach (XPathNavigator pytestResultNode in xmlTestResultNodes)
            {
                if (_cancelRequested.WaitOne(0))
                {
                    break;
                }
                try {
                    var pytestId = JunitXmlTestResultParser.GetPytestId(pytestResultNode);
                    if (pytestId != null && pytestIdToResultsMap.TryGetValue(pytestId, out TestResult vsTestResult))
                    {
                        JunitXmlTestResultParser.UpdateVsTestResult(vsTestResult, pytestResultNode);
                    }
                    else
                    {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, Strings.ErrorTestCaseNotFound.FormatUI(pytestResultNode.OuterXml));
                    }
                } catch (Exception ex) {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message);
                }
            }
        }
示例#6
0
        private IEnumerable <TestResult> ParseResults(
            string resultsXMLPath,
            IEnumerable <TestCase> testCases,
            IFrameworkHandle frameworkHandle
            )
        {
            // Default TestResults
            var pytestIdToResultsMap = testCases
                                       .Select(tc => new TestResult(tc)
            {
                Outcome = TestOutcome.Skipped
            })
                                       .ToDictionary(tr => tr.TestCase.GetPropertyValue <string>(Pytest.Constants.PytestIdProperty, String.Empty), tr => tr);

            if (File.Exists(resultsXMLPath))
            {
                try {
                    var doc = JunitXmlTestResultParser.Read(resultsXMLPath);
                    Parse(doc, pytestIdToResultsMap, frameworkHandle);
                } catch (Exception ex) {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message);
                }
            }
            else
            {
                frameworkHandle.SendMessage(TestMessageLevel.Error, Strings.PytestResultsXmlNotFound.FormatUI(resultsXMLPath));
            }

            return(pytestIdToResultsMap.Values);
        }
示例#7
0
        private void RunTestGroup(
            IGrouping <PythonProjectSettings, TestCase> testGroup,
            IRunContext runContext,
            IFrameworkHandle frameworkHandle
            )
        {
            PythonProjectSettings settings = testGroup.Key;

            if (settings == null || settings.TestFramework != TestFrameworkType.Pytest)
            {
                return;
            }

            using (var executor = new ExecutorService(settings, frameworkHandle, runContext)) {
                bool   codeCoverage = ExecutorService.EnableCodeCoverage(runContext);
                string covPath      = null;
                if (codeCoverage)
                {
                    covPath = ExecutorService.GetCoveragePath(testGroup);
                }

                var resultsXML = executor.Run(testGroup, covPath, _cancelRequested);

                // Default TestResults
                var pytestIdToResultsMap = testGroup.Select(tc => new TestResult(tc)
                {
                    Outcome = TestOutcome.Skipped
                })
                                           .ToDictionary(tr => tr.TestCase.GetPropertyValue <string>(Pytest.Constants.PytestIdProperty, String.Empty), tr => tr);

                if (File.Exists(resultsXML))
                {
                    try {
                        var doc = JunitXmlTestResultParser.Read(resultsXML);
                        Parse(doc, pytestIdToResultsMap, frameworkHandle);
                    } catch (Exception ex) {
                        frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message);
                    }
                }
                else
                {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, Strings.PytestResultsXmlNotFound.FormatUI(resultsXML));
                }

                foreach (var result in pytestIdToResultsMap.Values)
                {
                    if (_cancelRequested.WaitOne(0))
                    {
                        break;
                    }
                    frameworkHandle.RecordResult(result);
                }

                if (codeCoverage)
                {
                    ExecutorService.AttachCoverageResults(frameworkHandle, covPath);
                }
            }
        }
        private static TestResult ParseXmlTestUtil(string xmlResults)
        {
            var doc = new XmlDocument();

            doc.LoadXml(xmlResults);
            var result       = new TestResult(new TestCase());
            var testCaseIter = doc.CreateNavigator().SelectDescendants("testcase", "", false);

            testCaseIter.MoveNext();
            JunitXmlTestResultParser.UpdateVsTestResult(result, testCaseIter.Current);
            return(result);
        }
        public void PytestWrongXmlNodeThrowsException()
        {
            var testPass   = @"<testcase classname=""test_Parameters"" file=""test_Parameters.py"" line=""42"" name=""test_timedistance_v3[forward]"" time=""0.001""></testcase>";
            var xmlResults = string.Format(_junitXmlResultsFormat, testPass);

            var doc = new XmlDocument();

            doc.LoadXml(xmlResults);
            var result   = new TestResult(new TestCase());
            var rootNode = doc.CreateNavigator();

            JunitXmlTestResultParser.UpdateVsTestResult(result, rootNode);
        }
        public void CreatePytestIdMatchesDiscoveryPytestId()
        {
            var projectRoot = "c:\\home\\";
            var filename    = "Package1\\packageA\\Test1.py";
            var pytestId    = ".\\package1\\packageA\\test1.py::Test_test1::test_A";

            //Note: ignoring case since vsTestResult lookup ignores
            Assert.AreEqual(
                string.Compare(
                    PyTestExtensions.CreateProperCasedPytestId(projectRoot + filename, projectRoot, pytestId),
                    JunitXmlTestResultParser.CreatePytestId(filename.ToLower(), "package1.packageA.test1.Test_test1", "test_A"),
                    ignoreCase: true),
                0
                );
        }