private static void DiscoverTests(TestEnvironment testEnv, string[] sources, MockRunSettings runSettings, TestInfo[] expectedTests) { var discoveryContext = new MockDiscoveryContext(runSettings); var discoverySink = new MockTestCaseDiscoverySink(); var logger = new MockMessageLogger(); ITestDiscoverer discoverer = null; switch (testEnv.TestFramework) { case FrameworkPytest: discoverer = new PytestTestDiscoverer(); break; case FrameworkUnittest: discoverer = new UnittestTestDiscoverer(); break; default: Assert.Fail($"unknown testframework: {testEnv.TestFramework.ToString()}"); break; } discoverer.DiscoverTests(sources, discoveryContext, logger, discoverySink); ValidateDiscoveredTests(testEnv.TestFramework, discoverySink.Tests, expectedTests); }
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")); }
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" ); }
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 ); }
public void PytestShouldThrowNullResults() { var discoverer = new PytestTestDiscoverer(); var testcases = discoverer.ParseDiscoveryResults(null, projectHome: "dummypath"); testcases.Any(); }
public void PytestShouldHandleEmptyListResults() { var discoverer = new PytestTestDiscoverer(); var results = new List <PytestDiscoveryResults>(); var testcases = discoverer.ParseDiscoveryResults(results, projectHome: "dummypath"); Assert.IsFalse(testcases.Any()); }