diff --git a/tests/unit/test_test_runner.py b/tests/unit/test_test_runner.py index 1eaff104a..bf2c80b1d 100644 --- a/tests/unit/test_test_runner.py +++ b/tests/unit/test_test_runner.py @@ -11,6 +11,7 @@ from pathlib import Path import unittest from unittest import mock +from tempfile import TemporaryFile from tests.common import with_tempdir from vunit.hashing import hash_string from vunit.test.runner import TestRunner @@ -23,10 +24,13 @@ class TestTestRunner(unittest.TestCase): Test the test runner """ + def setUp(self): + self._run_script = TemporaryFile() + @with_tempdir def test_runs_testcases_in_order(self, tempdir): report = TestReport() - runner = TestRunner(report, tempdir) + runner = TestRunner(report, tempdir, self._run_script) order = [] test_case1 = self.create_test("test1", True, order=order) @@ -48,7 +52,7 @@ def test_runs_testcases_in_order(self, tempdir): @with_tempdir def test_fail_fast(self, tempdir): report = TestReport() - runner = TestRunner(report, tempdir, fail_fast=True) + runner = TestRunner(report, tempdir, self._run_script, fail_fast=True) order = [] test_case1 = self.create_test("test1", True, order=order) @@ -72,7 +76,7 @@ def test_fail_fast(self, tempdir): @with_tempdir def test_handles_python_exeception(self, tempdir): report = TestReport() - runner = TestRunner(report, tempdir) + runner = TestRunner(report, tempdir, self._run_script) test_case = self.create_test("test", True) test_list = TestList() @@ -88,7 +92,7 @@ def side_effect(*args, **kwargs): # pylint: disable=unused-argument @with_tempdir def test_collects_output(self, tempdir): report = TestReport() - runner = TestRunner(report, tempdir) + runner = TestRunner(report, tempdir, self._run_script) test_case = self.create_test("test", True) test_list = TestList() @@ -111,7 +115,7 @@ def side_effect(*args, **kwargs): # pylint: disable=unused-argument @with_tempdir def test_can_read_output(self, tempdir): report = TestReport() - runner = TestRunner(report, tempdir) + runner = TestRunner(report, tempdir, self._run_script) test_case = self.create_test("test", True) test_list = TestList() @@ -138,7 +142,7 @@ def side_effect(read_output, **kwargs): # pylint: disable=unused-argument def test_get_output_path_on_linux(self): output_path = "output_path" report = TestReport() - runner = TestRunner(report, output_path) + runner = TestRunner(report, output_path, self._run_script) with mock.patch("sys.platform", new="linux"): with mock.patch("os.environ", new={}): @@ -169,7 +173,7 @@ def test_get_output_path_on_linux(self): def test_get_output_path_on_windows(self): output_path = "output_path" report = TestReport() - runner = TestRunner(report, output_path) + runner = TestRunner(report, output_path, self._run_script) with mock.patch("sys.platform", new="win32"): with mock.patch("os.environ", new={}): @@ -213,6 +217,9 @@ def run_side_effect(*args, **kwargs): # pylint: disable=unused-argument test_case = TestCaseMock(name=name, run_side_effect=run_side_effect) return test_case + def tearDown(self): + self._run_script.close() + class TestCaseMock(object): """ @@ -226,7 +233,7 @@ def __init__(self, name, run_side_effect): self.called = False self.run_side_effect = run_side_effect - def run(self, output_path, read_output): + def run(self, output_path, read_output, run_script_path): """ Mock run method that just records the arguments """