From eb0d559434ae711b98e7eb4c781751a0f4d7de40 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 24 Jul 2020 14:33:08 +0100 Subject: [PATCH] calling the test dictionary from the constructor is effectively what unittest does. this results in multiple copies of the test being called (once by the dictionary-loop, once by unittest infrastructure) getting the name of the actual test is a good thing. used inspect.stack() to find the name of the calling test --- src/soc/fu/div/test/test_all_pipe_caller.py | 9 +++------ src/soc/fu/div/test/test_pipe_caller.py | 10 +++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/soc/fu/div/test/test_all_pipe_caller.py b/src/soc/fu/div/test/test_all_pipe_caller.py index 31bea464..86eb29d2 100644 --- a/src/soc/fu/div/test/test_all_pipe_caller.py +++ b/src/soc/fu/div/test/test_all_pipe_caller.py @@ -1,4 +1,5 @@ import random +import inspect import unittest from soc.simulator.program import Program from soc.config.endian import bigendian @@ -11,14 +12,10 @@ class DivTestLong(unittest.TestCase): test_data = [] def __init__(self, name): super().__init__(name) - for n, v in self.__class__.__dict__.items(): - if n.startswith("test") and callable(v): - self._current_test_name = n - v(self) def run_test_program(self, prog, initial_regs=None, initial_sprs=None): - tc = TestCase(prog, self._current_test_name, - initial_regs, initial_sprs) + test_name = inspect.stack()[1][3] # name of caller of this function + tc = TestCase(prog, test_name, initial_regs, initial_sprs) self.test_data.append(tc) def test_all(self): diff --git a/src/soc/fu/div/test/test_pipe_caller.py b/src/soc/fu/div/test/test_pipe_caller.py index 573816ff..9bb54e23 100644 --- a/src/soc/fu/div/test/test_pipe_caller.py +++ b/src/soc/fu/div/test/test_pipe_caller.py @@ -1,3 +1,4 @@ +import inspect import random import unittest from nmutil.formaltest import FHDLTestCase @@ -24,14 +25,9 @@ class DivTestCases(unittest.TestCase): def __init__(self, name): super().__init__(name) - for n, v in self.__class__.__dict__.items(): - if n.startswith("test") and callable(v): - self._current_test_name = n - v(self) - def run_test_program(self, prog, initial_regs=None, initial_sprs=None): - tc = TestCase(prog, self._current_test_name, - initial_regs, initial_sprs) + test_name = inspect.stack()[1][3] # name of caller of this function + tc = TestCase(prog, test_name, initial_regs, initial_sprs) self.test_data.append(tc) def test_0_regression(self): -- 2.30.2