[PATCH] D68921: [LNT] Python 3 support: fix server/ui/statsTester.py test discovery

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 12 15:46:45 PDT 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.

Unit test server/ui/statsTester.py is invoked with an extra parameter
which confuses unittest test discovery. Indeed, when parameter
defaultTest of unittest.main() method is in its default value the test
to run is taken from argv parameter if not empty. argv parameter in turn
defaults to sys.argv and thus unittest will take the first parameter for
the name of the test to execute.

Under Python 2 this would throw an AttributeError which would pass
through all the way up to the test itself which contains a catch to
remove the parameter and try again. Note that the exception is not
documented. Under Python 3 the exception is caught by the unittest
framework which exits with an error.

Since the parameter that confuses the test discovery is a temporary
LNT instance directory which is not used by the test, this commit simply
removes these LIT steps and only call the unittest without parameter.


https://reviews.llvm.org/D68921

Files:
  tests/server/ui/statsTester.py


Index: tests/server/ui/statsTester.py
===================================================================
--- tests/server/ui/statsTester.py
+++ tests/server/ui/statsTester.py
@@ -1,13 +1,4 @@
-#
-# create temporary instance
-# Cleanup temporary directory in case one remained from a previous run - also
-# see PR9904.
-# RUN: rm -rf %t.instance
-# RUN: python %{shared_inputs}/create_temp_instance.py \
-# RUN:   %s %{shared_inputs}/SmallInstance %t.instance \
-# RUN:   %S/Inputs/V4Pages_extra_records.sql
-#
-# RUN: python %s %t.instance
+# RUN: python %s
 
 import unittest
 
@@ -54,13 +45,4 @@
 
 
 if __name__ == '__main__':
-    try:
-        unittest.main()
-    except AttributeError:
-        # Command line parameters are treated as test cases, when \
-        # running with lit rather than python directly.
-        import sys
-        if len(sys.argv) != 2:
-            sys.exit("Something went horribly wrong. You need parameters.")
-        del sys.argv[1:]
-        unittest.main()
+    unittest.main()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68921.224762.patch
Type: text/x-patch
Size: 1021 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191012/ce786550/attachment.bin>


More information about the llvm-commits mailing list