From: Luke Kenneth Casson Leighton Date: Fri, 24 Jul 2020 13:33:08 +0000 (+0100) Subject: calling the test dictionary from the constructor is effectively X-Git-Tag: semi_working_ecp5~570 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=eb0d559434ae711b98e7eb4c781751a0f4d7de40;p=soc.git 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 --- 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):