Repository: cocotb/cocotb

Issue:
Test names are incorrect in summary
From https://github.com/cocotb/cocotb/pull/1380#issuecomment-599155133. Introduced in #1262. It's due to all the unnecessary monkeying the decorators and regression manager do to compute a name. The PR changed how the module name is passed to `_store_test_result`. It uses `__module__`, but on `RunningTest`s that value is `cocotb.decorator` instead of the module name of the underlying function. 


Discussion:
`RunningTest` mostly exists for use by the regression manager. It really doesn't need all the extra attributes on it, they already exist on the `test` object. The regression manager should be changed to just work off `test` objects instead of stuffing all the info it needs from that object into yet another object. `RunningTest` and `RunningCoroutine` should just go away entirely. I think this will require a change to the scheduler as well as the regression manager due to how `handle_result` works. The relationship between the scheduler and regression manager are just very very irregular...
To be clear, you're advocating that `RunningTest` and `RunningCoroutine` should both be replaced with their `RunningTask` baseclass, which doesn't have any of the weird attributes.

> The relationship between the scheduler and regression manager are just very very irregular...

What I'd eventually like to happen is for the regression manager to just be a single coroutine run by the scheduler, with the weirdness wrapped into a few new scheduler methods or context managers 
@eric-wieser Yes, deprecate `RunningTest` and `RunningCoroutine` and change the decorators to create `RunningTasks` in their place. The regression manager could simply `fork` a test "watcher", which in turn waits for the test coroutine to finish and record the outcome. I don't think we need any additional scheduler features to support that, and we could segregate the two objects by removing "test" code from the scheduler.
We need a feature to collect and kill all coroutines forked by the test before starting the next one, which is currently embedded in the scheduler.
I think we should destroy the scheduler between tests and have each trigger/coroutine clean itself up. But don't we already have `finish_scheduler` for cleanup anyways?

Resolving patch:
diff --git a/cocotb/regression.py b/cocotb/regression.py
--- a/cocotb/regression.py
+++ b/cocotb/regression.py
@@ -216,7 +216,7 @@ def tear_down(self):
                                     sim_time_ns=repr(0),
                                     ratio_time=repr(0))
             result_pass, _ = self._score_test(test, cocotb.outcomes.Error(SimFailure()))
-            self._store_test_result(test.__module__, test.__name__, result_pass, 0, 0, 0)
+            self._store_test_result(test.module, test.funcname, result_pass, 0, 0, 0)
             if not result_pass:
                 self.xunit.add_failure()
                 self.failures += 1
@@ -277,7 +277,7 @@ def handle_result(self, test):
         cocotb.log.removeHandler(test.handler)
 
         # Save results
-        self._store_test_result(test.__module__, test.__name__, result_pass, sim_time_ns, real_time, ratio_time)
+        self._store_test_result(test.module, test.funcname, result_pass, sim_time_ns, real_time, ratio_time)
         if not result_pass:
             self.xunit.add_failure()
             self.failures += 1


Test patch: