aboutsummaryrefslogtreecommitdiff
path: root/unittests
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-05-02 22:44:54 -0400
committerEli Schwartz <eschwartz@archlinux.org>2023-05-02 22:51:57 -0400
commit9dbe718eb64ea136f3a7db03b305df5831792631 (patch)
tree8dded98e5c881fc8a6d4e16817fbda53ad6b111c /unittests
parent4e17d60d47357b7e3a4fd772ce031cd7cd7bc57e (diff)
downloadmeson-9dbe718eb64ea136f3a7db03b305df5831792631.zip
meson-9dbe718eb64ea136f3a7db03b305df5831792631.tar.gz
meson-9dbe718eb64ea136f3a7db03b305df5831792631.tar.bz2
unittests: add magic flag global to integrate utility methods with unittest
The stdlib unittest module has a magic flag (undocumented) which indicates that a module is part of a unittest framework. > Truncates usercode tb at the first unittest frame. > > If the first frame of the traceback is in user code, > the prefix up to the first unittest frame is returned. > If the first frame is already in the unittest module, > the traceback is not modified. This avoids some ugliness, e.g. the following test error logs: ``` > self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.aaa']) unittests/allplatformstests.py:432: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ unittests/baseplatformtests.py:393: in assertPathListEqual self.assertPathEqual(i[0], i[1]) unittests/baseplatformtests.py:384: in assertPathEqual self.assertEqual(PurePath(path1), PurePath(path2)) E AssertionError: PurePosixPath('/usr/lib/libstat.a') != PurePosixPath('/usr/lib/libstat.aaa') ``` Since assertPathListEqual is our own assertion helper, we don't need to give trace information about its internals. This change causes the error log to become: ``` > self.assertPathListEqual(intro[0]['install_filename'], ['/usr/lib/libstat.aaa']) E AssertionError: PurePosixPath('/usr/lib/libstat.a') != PurePosixPath('/usr/lib/libstat.aaa') unittests/allplatformstests.py:432: AssertionError ``` which is a lot more readable.
Diffstat (limited to 'unittests')
-rw-r--r--unittests/baseplatformtests.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/unittests/baseplatformtests.py b/unittests/baseplatformtests.py
index b3572df..251c15d 100644
--- a/unittests/baseplatformtests.py
+++ b/unittests/baseplatformtests.py
@@ -45,6 +45,11 @@ from run_tests import (
)
+# magic attribute used by unittest.result.TestResult._is_relevant_tb_level
+# This causes tracebacks to hide these internal implementation details,
+# e.g. for assertXXX helpers.
+__unittest = True
+
class BasePlatformTests(TestCase):
prefix = '/usr'
libdir = 'lib'