<p>neels <strong>submitted</strong> this change.</p><p><a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/21541">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  pespin: Looks good to me, approved

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">fix: line nr in test name in wrong places<br><br>test.Test() overrides name() in order to provide source line number<br>information. However, overriding name() is the wrong place for that, as<br>name() is also often used for identifying an object - when listing the<br>tests of a suite, the line number should not appear in the test name.<br>For example, the line number sometimes ends up in the test results in<br>jenkins, making 'foo.py' and 'foo.py:23' two distinct report items.<br><br>Instead, add a separate function Origin.src() that defaults to name(),<br>but specific classes can override src() if they wish to provide more<br>detailed information with the object name.<br><br>Override src() in Test, not name().<br><br>Use src() in backtraces.<br><br>The suite_test.ok shows that the backtracing in the log remains<br>unchanged, but the place where the test name is printed is corrected:<br>   I am 'test_suite' / 'hello_world.py:23'<br>becomes<br>   I am 'test_suite' / 'hello_world.py'<br>(Notice that "[LINENR]" in suite_test.ok is a masking of an actual<br>number, done within the selftest suite)<br><br>Change-Id: I0c4698fa2b3db3de777d8b6dcdcee84e433c62b7<br>---<br>M selftest/suite_test/suite_test.ok<br>M src/osmo_gsm_tester/core/log.py<br>M src/osmo_gsm_tester/core/test.py<br>3 files changed, 17 insertions(+), 11 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/selftest/suite_test/suite_test.ok b/selftest/suite_test/suite_test.ok</span><br><span>index dfc8d41..2c49c19 100644</span><br><span>--- a/selftest/suite_test/suite_test.ok</span><br><span>+++ b/selftest/suite_test/suite_test.ok</span><br><span>@@ -160,7 +160,7 @@</span><br><span> trial test_suite hello_world.py</span><br><span> ----------------------------------------------</span><br><span> tst hello_world.py:[LINENR]: hello world  [test_suite↪hello_world.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py:[LINENR]'  [test_suite↪hello_world.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py'  [test_suite↪hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: one  [test_suite↪hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: two  [test_suite↪hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: three  [test_suite↪hello_world.py:[LINENR]]</span><br><span>@@ -187,7 +187,7 @@</span><br><span> ----------------------------------------------</span><br><span> trial test_suite test_error.py</span><br><span> ----------------------------------------------</span><br><span style="color: hsl(0, 100%, 40%);">-tst test_error.py:[LINENR]: I am 'test_suite' / 'test_error.py:[LINENR]'  [test_suite↪test_error.py:[LINENR]]  [test_error.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_error.py:[LINENR]: I am 'test_suite' / 'test_error.py'  [test_suite↪test_error.py:[LINENR]]  [test_error.py:[LINENR]]</span><br><span> tst test_error.py:[LINENR]: ERR: AssertionError: test_error.py:[LINENR]: assert False  [test_suite↪test_error.py:[LINENR]]  [test_error.py:[LINENR]: assert False]</span><br><span> tst test_error.py:[LINENR]: Test FAILED (N.N sec)  [test_suite↪test_error.py:[LINENR]]  [test.py:[LINENR]]</span><br><span> ---------------------------------------------------------------------</span><br><span>@@ -212,7 +212,7 @@</span><br><span> ----------------------------------------------</span><br><span> trial test_suite test_fail.py</span><br><span> ----------------------------------------------</span><br><span style="color: hsl(0, 100%, 40%);">-tst test_fail.py:[LINENR]: I am 'test_suite' / 'test_fail.py:[LINENR]'  [test_suite↪test_fail.py:[LINENR]]  [test_fail.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst test_fail.py:[LINENR]: I am 'test_suite' / 'test_fail.py'  [test_suite↪test_fail.py:[LINENR]]  [test_fail.py:[LINENR]]</span><br><span> tst test_fail.py:[LINENR]: ERR: EpicFail: This failure is expected  [test_suite↪test_fail.py:[LINENR]]  [test_fail.py:[LINENR]]</span><br><span> tst test_fail.py:[LINENR]: Test FAILED (N.N sec)  [test_suite↪test_fail.py:[LINENR]]  [test.py:[LINENR]]</span><br><span> ---------------------------------------------------------------------</span><br><span>@@ -389,7 +389,7 @@</span><br><span> trial test_suite hello_world.py</span><br><span> ----------------------------------------------</span><br><span> tst hello_world.py:[LINENR]: hello world  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py:[LINENR]'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: one  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: two  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: three  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span>@@ -544,7 +544,7 @@</span><br><span> trial test_suite hello_world.py</span><br><span> ----------------------------------------------</span><br><span> tst hello_world.py:[LINENR]: hello world  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py:[LINENR]'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: one  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: two  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: three  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span>@@ -745,7 +745,7 @@</span><br><span> trial test_suite hello_world.py</span><br><span> ----------------------------------------------</span><br><span> tst hello_world.py:[LINENR]: hello world  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(0, 100%, 40%);">-tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py:[LINENR]'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span style="color: hsl(120, 100%, 40%);">+tst hello_world.py:[LINENR]: I am 'test_suite' / 'hello_world.py'  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: one  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: two  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span> tst hello_world.py:[LINENR]: three  [test_suite↪hello_world.py:[LINENR]]  [hello_world.py:[LINENR]]</span><br><span>diff --git a/src/osmo_gsm_tester/core/log.py b/src/osmo_gsm_tester/core/log.py</span><br><span>index b8182f5..2b8db62 100644</span><br><span>--- a/src/osmo_gsm_tester/core/log.py</span><br><span>+++ b/src/osmo_gsm_tester/core/log.py</span><br><span>@@ -222,7 +222,7 @@</span><br><span>             if origin is None:</span><br><span>                 name = '-'</span><br><span>             elif isinstance(origin, Origin):</span><br><span style="color: hsl(0, 100%, 40%);">-                name = origin.name()</span><br><span style="color: hsl(120, 100%, 40%);">+                name = origin.src()</span><br><span>                 # only log ancestry when there is more than one</span><br><span>                 if origin._parent is not None:</span><br><span>                     deeper_origins = origin.ancestry_str()</span><br><span>@@ -447,6 +447,12 @@</span><br><span>     def name(self):</span><br><span>         return self._name or self.__class__.__name__</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+    def src(self):</span><br><span style="color: hsl(120, 100%, 40%);">+        '''subclasses may override this to provide more detailed source</span><br><span style="color: hsl(120, 100%, 40%);">+        information with the name, for a backtrace. For example, a line number</span><br><span style="color: hsl(120, 100%, 40%);">+        in a test script.'''</span><br><span style="color: hsl(120, 100%, 40%);">+        return self.name()</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     __str__ = name</span><br><span>     __repr__ = name</span><br><span> </span><br><span>@@ -476,7 +482,7 @@</span><br><span>         return origins</span><br><span> </span><br><span>     def ancestry_str(self):</span><br><span style="color: hsl(0, 100%, 40%);">-        return '↪'.join([o.name() for o in self.ancestry()])</span><br><span style="color: hsl(120, 100%, 40%);">+        return '↪'.join([o.src() for o in self.ancestry()])</span><br><span> </span><br><span>     def highest_ancestor(self):</span><br><span>         if self._parent:</span><br><span>diff --git a/src/osmo_gsm_tester/core/test.py b/src/osmo_gsm_tester/core/test.py</span><br><span>index fd3ac04..896eb4c 100644</span><br><span>--- a/src/osmo_gsm_tester/core/test.py</span><br><span>+++ b/src/osmo_gsm_tester/core/test.py</span><br><span>@@ -102,11 +102,11 @@</span><br><span>             for log_tgt in self.log_targets:</span><br><span>                 log_tgt.remove()</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    def name(self):</span><br><span style="color: hsl(120, 100%, 40%);">+    def src(self):</span><br><span>         l = log.get_line_for_src(self.path)</span><br><span>         if l is not None:</span><br><span style="color: hsl(0, 100%, 40%);">-            return '%s:%s' % (self._name, l)</span><br><span style="color: hsl(0, 100%, 40%);">-        return super().name()</span><br><span style="color: hsl(120, 100%, 40%);">+            return '%s:%s' % (self.name(), l)</span><br><span style="color: hsl(120, 100%, 40%);">+        return self.name()</span><br><span> </span><br><span>     def elapsed_time(self):</span><br><span>         'time elapsed since test was started'</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/21541">change 21541</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/c/osmo-gsm-tester/+/21541"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-gsm-tester </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I0c4698fa2b3db3de777d8b6dcdcee84e433c62b7 </div>
<div style="display:none"> Gerrit-Change-Number: 21541 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: neels <nhofmeyr@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder </div>
<div style="display:none"> Gerrit-Reviewer: pespin <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>