示例#1
0
        public void Run(IEnumerable <TestCase> tests, ManualResetEvent cancelRequested)
        {
            bool   codeCoverage = CodeCoverage.EnableCodeCoverage(_runContext);
            string coveragePath = null;

            if (codeCoverage)
            {
                coveragePath = CodeCoverage.GetCoveragePath(tests);
            }

            RunInternal(tests, coveragePath, cancelRequested);

            if (codeCoverage)
            {
                CodeCoverage.AttachCoverageResults(_frameworkHandle, coveragePath);
            }
        }
示例#2
0
        internal static string GetCoveragePath(IEnumerable <TestCase> tests)
        {
            string bestFile = null, bestClass = null, bestMethod = null;

            // Try and generate a friendly name for the coverage report.  We use
            // the filename, class, and method.  We include each one if we're
            // running from a single filename/class/method.  When we have multiple
            // we drop the identifying names.  If we have multiple files we
            // go to the top level directory...  If all else fails we do "pycov".
            foreach (var test in tests)
            {
                string testFile, testClass, testMethod;
                TestReader.ParseFullyQualifiedTestName(
                    test.FullyQualifiedName,
                    out testFile,
                    out testClass,
                    out testMethod
                    );

                bestFile = CodeCoverage.UpdateBestFile(bestFile, test.CodeFilePath);
                if (bestFile != test.CodeFilePath)
                {
                    // Different files, don't include class/methods even
                    // if they happen to be the same.
                    bestClass = bestMethod = "";
                }

                bestClass  = CodeCoverage.UpdateBest(bestClass, testClass);
                bestMethod = CodeCoverage.UpdateBest(bestMethod, testMethod);
            }

            string filename = "";

            if (!String.IsNullOrWhiteSpace(bestFile))
            {
                if (ModulePath.IsPythonSourceFile(bestFile))
                {
                    filename = ModulePath.FromFullPath(bestFile).ModuleName;
                }
                else
                {
                    filename = Path.GetFileName(bestFile);
                }
            }
            else
            {
                filename = "pycov";
            }

            if (!String.IsNullOrWhiteSpace(bestClass))
            {
                filename += "_" + bestClass;
            }

            if (!String.IsNullOrWhiteSpace(bestMethod))
            {
                filename += "_" + bestMethod;
            }

            filename += "_" + DateTime.Now.ToString("s").Replace(':', '_');

            return(Path.Combine(Path.GetTempPath(), filename));
        }