Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
                }
            }
        }