From b671f6282f034199bef5870b31537f1b52dd582b Mon Sep 17 00:00:00 2001 From: Eugene Toder Date: Wed, 10 Apr 2024 20:08:43 -0400 Subject: [PATCH] Fix test_time being always 0.0 The bug was introduced in commit 651ab467e371b42e6205b9c3d223f2e1f50e4b0a when setting start_time = 0.0 was added to ProtoTestResult.reinitialize(). --- green/result.py | 2 +- green/test/test_process.py | 10 ++++++---- green/test/test_result.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/green/result.py b/green/result.py index 1e9e605..964c39d 100644 --- a/green/result.py +++ b/green/result.py @@ -329,8 +329,8 @@ def startTest(self, test: RunnableTestT) -> None: Called before each test runs. """ test = proto_test(test) - self.start_time = time.time() self.reinitialize() + self.start_time = time.time() if self.start_callback: self.start_callback(test) diff --git a/green/test/test_process.py b/green/test/test_process.py index d2852a7..976bbf3 100644 --- a/green/test/test_process.py +++ b/green/test/test_process.py @@ -103,10 +103,12 @@ def testPass(self): ) fh.close() module_name = basename + ".test_pool_runner_dotted.A.testPass" - result = Queue() - poolRunner(module_name, result, 1) - result.get() - self.assertEqual(len(result.get().passing), 1) + results = Queue() + poolRunner(module_name, results, 1) + results.get() + result = results.get() + self.assertEqual(len(result.passing), 1) + self.assertGreater(float(result.test_time), 0) def test_SyntaxErrorInUnitTest(self): """ diff --git a/green/test/test_result.py b/green/test/test_result.py index 07739b0..c9f87fb 100644 --- a/green/test/test_result.py +++ b/green/test/test_result.py @@ -104,6 +104,16 @@ def test_displayStderr(self): class TestProtoTestResult(unittest.TestCase): + def test_startStop(self): + """ + startTest/stopTest work correctly + """ + ptr = ProtoTestResult() + test = proto_test(MagicMock()) + ptr.startTest(test) + ptr.stopTest(test) + self.assertGreater(float(ptr.test_time), 0) + def test_addSuccess(self): """ addSuccess adds a test correctly