2018-03-27 14:30:46 -04:00
|
|
|
"""The unittest.TestCase for Python unittests."""
|
2024-05-16 18:00:17 -04:00
|
|
|
|
2018-04-04 14:19:19 -04:00
|
|
|
import os
|
2019-04-15 16:09:15 -04:00
|
|
|
import sys
|
2018-04-04 14:19:19 -04:00
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
from buildscripts.resmokelib import core, logging
|
2018-04-04 14:19:19 -04:00
|
|
|
from buildscripts.resmokelib.testing.testcases import interface
|
|
|
|
|
|
|
|
|
|
|
2019-04-15 16:09:15 -04:00
|
|
|
class PyTestCase(interface.ProcessTestCase):
|
2018-03-27 14:30:46 -04:00
|
|
|
"""A python test to execute."""
|
2018-04-04 14:19:19 -04:00
|
|
|
|
|
|
|
|
REGISTERED_NAME = "py_test"
|
|
|
|
|
|
2024-05-14 11:07:04 -07:00
|
|
|
def __init__(self, logger: logging.Logger, py_filenames: list[str]):
|
2018-03-27 14:30:46 -04:00
|
|
|
"""Initialize PyTestCase."""
|
2024-05-14 11:07:04 -07:00
|
|
|
assert len(py_filenames) == 1
|
|
|
|
|
interface.ProcessTestCase.__init__(self, logger, "PyTest", py_filenames[0])
|
2018-04-04 14:19:19 -04:00
|
|
|
|
2019-04-15 16:09:15 -04:00
|
|
|
def _make_process(self):
|
2025-08-26 15:42:07 -04:00
|
|
|
program_options = {}
|
|
|
|
|
interface.append_process_tracking_options(program_options, self._id)
|
2019-04-15 16:09:15 -04:00
|
|
|
return core.programs.generic_program(
|
2025-08-26 15:42:07 -04:00
|
|
|
self.logger, [sys.executable, "-m", "unittest", self.test_module_name], program_options
|
2024-05-16 18:00:17 -04:00
|
|
|
)
|
2018-04-04 14:19:19 -04:00
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def test_module_name(self):
|
|
|
|
|
"""Get the dotted module name from the path."""
|
|
|
|
|
return os.path.splitext(self.test_name)[0].replace(os.sep, ".")
|