Ejemplo n.º 1
0
        public void DiscoverPytestSyntaxErrorLogErrors()
        {
            // one file has a valid passing test,
            // the other has a test with a syntax error in it
            var testEnv = TestEnvironment.GetOrCreate(Version, FrameworkPytest);

            FileUtils.CopyDirectory(TestData.GetPath("TestData", "TestDiscoverer", "SyntaxErrorPytest"), testEnv.SourceFolderPath);

            var testFilePath1 = Path.Combine(testEnv.SourceFolderPath, "test_basic.py");
            var testFilePath2 = Path.Combine(testEnv.SourceFolderPath, "test_syntax_error.py");

            var expectedTests = new[] {
                new TestInfo("test_success", "test_basic.py::test_basic::test_success", testFilePath1, 1),
            };

            var runSettings = new MockRunSettings(
                new MockRunSettingsXmlBuilder(testEnv.TestFramework, testEnv.InterpreterPath, testEnv.ResultsFolderPath, testEnv.SourceFolderPath)
                .WithTestFile(testFilePath1)
                .WithTestFile(testFilePath2)
                .ToXml()
                );

            var discoveryContext = new MockDiscoveryContext(runSettings);
            var discoverySink    = new MockTestCaseDiscoverySink();
            var logger           = new MockMessageLogger();
            var discoverer       = new PytestTestDiscoverer();

            discoverer.DiscoverTests(new[] { testFilePath1, testFilePath2 }, discoveryContext, logger, discoverySink);

            var errors = string.Join(Environment.NewLine, logger.GetErrors());

            AssertUtil.Contains(errors,
                                "SyntaxError: invalid syntax"
                                );
        }
Ejemplo n.º 2
0
        public void DiscoverPytestNotInstalled()
        {
            var testEnv = TestEnvironment.GetOrCreate(Version, FrameworkPytest, installFramework: false);

            var testFilePath = Path.Combine(testEnv.SourceFolderPath, "test_pt.py");

            File.Copy(TestData.GetPath("TestData", "TestDiscoverer", "BasicPytest", "test_pt.py"), testFilePath);

            var runSettings = new MockRunSettings(
                new MockRunSettingsXmlBuilder(testEnv.TestFramework, testEnv.InterpreterPath, testEnv.ResultsFolderPath, testEnv.SourceFolderPath)
                .WithTestFilesFromFolder(testEnv.SourceFolderPath)
                .ToXml()
                );

            var discoveryContext = new MockDiscoveryContext(runSettings);
            var discoverySink    = new MockTestCaseDiscoverySink();
            var logger           = new MockMessageLogger();
            var discoverer       = new PytestTestDiscoverer();

            discoverer.DiscoverTests(new[] { testFilePath }, discoveryContext, logger, discoverySink);
            Assert.AreEqual(0, discoverySink.Tests.Count);

            var errors = string.Join(Environment.NewLine, logger.GetErrors());

            AssertUtil.Contains(errors, string.Format(ImportErrorFormat, "pytest"));
        }
Ejemplo n.º 3
0
        public void DiscoverPytestTimeoutError()
        {
            var testEnv = TestEnvironment.GetOrCreate(Version, FrameworkPytest);

            var testFilePath = Path.Combine(testEnv.SourceFolderPath, "test_timeout_pt.py");

            File.Copy(TestData.GetPath("TestData", "TestDiscoverer", "Timeout", "test_timeout_pt.py"), testFilePath);

            int waitTimeInSeconds = 1;
            var runSettings       = new MockRunSettings(
                new MockRunSettingsXmlBuilder(testEnv.TestFramework, testEnv.InterpreterPath, testEnv.ResultsFolderPath, testEnv.SourceFolderPath, waitTimeInSeconds)
                .WithTestFilesFromFolder(testEnv.SourceFolderPath)
                .ToXml()
                );

            var discoveryContext = new MockDiscoveryContext(runSettings);
            var discoverySink    = new MockTestCaseDiscoverySink();
            var logger           = new MockMessageLogger();
            var discoverer       = new PytestTestDiscoverer();

            discoverer.DiscoverTests(new[] { testFilePath }, discoveryContext, logger, discoverySink);
            Assert.AreEqual(0, discoverySink.Tests.Count);

            var errors = string.Join(Environment.NewLine, logger.GetErrors());

            AssertUtil.Contains(
                errors,
                Strings.PythonTestDiscovererTimeoutErrorMessage
                );
        }