summaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorJonathan Abrahams <jonathan@mongodb.com>2019-04-15 16:09:15 -0400
committerJonathan Abrahams <jonathan@mongodb.com>2019-04-16 16:44:21 -0400
commit22578319a59e898dc67d7de88531a5c23f2273ce (patch)
treebf7b508500970230f60e7e14ec6cd7d412f38bf3 /buildscripts
parentd48f6caba6f97a578828d89ec2b95c41cbc5c67a (diff)
downloadmongo-22578319a59e898dc67d7de88531a5c23f2273ce.tar.gz
SERVER-40339 Log buildscripts_test output in test logs
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/resmokelib/testing/testcases/pytest.py23
-rw-r--r--buildscripts/tests/resmokelib/testing/testcases/__init__.py1
-rw-r--r--buildscripts/tests/resmokelib/testing/testcases/test_pytest.py71
-rw-r--r--buildscripts/tests/util/test_time.py2
4 files changed, 80 insertions, 17 deletions
diff --git a/buildscripts/resmokelib/testing/testcases/pytest.py b/buildscripts/resmokelib/testing/testcases/pytest.py
index 94da3a8c939..46cd7d5afa8 100644
--- a/buildscripts/resmokelib/testing/testcases/pytest.py
+++ b/buildscripts/resmokelib/testing/testcases/pytest.py
@@ -1,32 +1,23 @@
"""The unittest.TestCase for Python unittests."""
import os
-import unittest
+import sys
+from buildscripts.resmokelib import core
from buildscripts.resmokelib.testing.testcases import interface
-class PyTestCase(interface.TestCase):
+class PyTestCase(interface.ProcessTestCase):
"""A python test to execute."""
REGISTERED_NAME = "py_test"
def __init__(self, logger, py_filename):
"""Initialize PyTestCase."""
- interface.TestCase.__init__(self, logger, "PyTest", py_filename)
+ interface.ProcessTestCase.__init__(self, logger, "PyTest", py_filename)
- def run_test(self):
- """Execute the test."""
- suite = unittest.defaultTestLoader.loadTestsFromName(self.test_module_name)
- result = unittest.TextTestRunner().run(suite)
- if not result.wasSuccessful():
- msg = "Python test {} failed".format(self.test_name)
- raise self.failureException(msg)
-
- self.return_code = 0
-
- def as_command(self):
- """Return execute command."""
- return "python -m unittest {}".format(self.test_module_name)
+ def _make_process(self):
+ return core.programs.generic_program(
+ self.logger, [sys.executable, "-m", "unittest", self.test_module_name])
@property
def test_module_name(self):
diff --git a/buildscripts/tests/resmokelib/testing/testcases/__init__.py b/buildscripts/tests/resmokelib/testing/testcases/__init__.py
new file mode 100644
index 00000000000..4b7a2bb941b
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/testcases/__init__.py
@@ -0,0 +1 @@
+"""Empty."""
diff --git a/buildscripts/tests/resmokelib/testing/testcases/test_pytest.py b/buildscripts/tests/resmokelib/testing/testcases/test_pytest.py
new file mode 100644
index 00000000000..9b5d00b18cc
--- /dev/null
+++ b/buildscripts/tests/resmokelib/testing/testcases/test_pytest.py
@@ -0,0 +1,71 @@
+"""Unit tests for the buildscripts.resmokelib.testing.testcases.pytest module."""
+import logging
+import sys
+import unittest
+
+from mock import MagicMock, patch
+
+from buildscripts.resmokelib.testing.testcases import pytest
+
+_IS_WINDOWS = sys.platform == "win32"
+
+# pylint: disable=missing-docstring,protected-access
+
+
+def get_filename(filename):
+ if _IS_WINDOWS:
+ return filename.replace("/", "\\")
+ return filename
+
+
+class TestPyTestCase(unittest.TestCase):
+ def test__make_process(self):
+ logger = logging.getLogger("pytest")
+ filename = "myfile.py"
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_name, filename)
+ self.assertEqual(pytest_case.logger, logger)
+ proc = pytest_case._make_process()
+ self.assertIn(sys.executable + " -m unittest", proc.as_command())
+ self.assertIn(pytest_case.test_module_name, proc.as_command())
+ self.assertEqual(proc.logger, logger)
+
+ def test__make_process_dir(self):
+ logger = logging.getLogger("pytest")
+ filename = "dir1/dir2/myfile.py"
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_name, filename)
+ self.assertEqual(pytest_case.logger, logger)
+ proc = pytest_case._make_process()
+ self.assertIn(sys.executable + " -m unittest", proc.as_command())
+ self.assertIn(pytest_case.test_module_name, proc.as_command())
+ self.assertEqual(proc.logger, logger)
+
+ def test__make_process_windows_file(self):
+ logger = logging.getLogger("pytest")
+ filename = "dir1\\dir2\\myfile.py"
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_name, filename)
+ self.assertEqual(pytest_case.logger, logger)
+ proc = pytest_case._make_process()
+ self.assertIn(sys.executable + " -m unittest", proc.as_command())
+ self.assertIn(pytest_case.test_module_name, proc.as_command())
+ self.assertEqual(proc.logger, logger)
+
+ def test_test_module_name(self):
+ logger = logging.getLogger("pytest")
+ filename = get_filename("dir1/dir2/dir3/myfile.py")
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_module_name, "dir1.dir2.dir3.myfile")
+
+ def test_test_module_name_absolute_dir(self):
+ logger = logging.getLogger("pytest")
+ filename = get_filename("/dir1/dir2/dir3/myfile.py")
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_module_name, ".dir1.dir2.dir3.myfile")
+
+ def test_test_module_name_no_dir(self):
+ logger = logging.getLogger("pytest")
+ filename = "myfile.py"
+ pytest_case = pytest.PyTestCase(logger, filename)
+ self.assertEqual(pytest_case.test_module_name, "myfile")
diff --git a/buildscripts/tests/util/test_time.py b/buildscripts/tests/util/test_time.py
index 78fc59bc01f..a405176bc60 100644
--- a/buildscripts/tests/util/test_time.py
+++ b/buildscripts/tests/util/test_time.py
@@ -2,7 +2,7 @@
import unittest
-import util.time as time_utils
+from buildscripts.util import time as time_utils
#pylint: disable=missing-docstring