Skip to content

Commit 7ad675d

Browse files
committed
Add test_main among tests
1 parent 5c1378b commit 7ad675d

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
import os
41+
import sys
42+
import unittest
43+
44+
sys.path.insert(0, os.getcwd())
45+
46+
47+
class TestLoader(unittest.TestLoader):
48+
def loadTestsFromModule(self, module, pattern=None):
49+
suite = super().loadTestsFromModule(module, pattern=pattern)
50+
test_main = getattr(module, 'test_main', None)
51+
if callable(test_main):
52+
class TestMain(unittest.TestCase):
53+
pass
54+
55+
TestMain.__module__ = test_main.__module__
56+
TestMain.__qualname__ = TestMain.__name__
57+
TestMain.test_main = staticmethod(test_main)
58+
suite.addTests(self.loadTestsFromTestCase(TestMain))
59+
return suite
60+
61+
62+
# We would normmally just pass the loader to the main, but there are tests for the framework itself (test_unittest)
63+
# that interact weirdly with non-default loaders
64+
unittest.defaultTestLoader = TestLoader()
65+
unittest.main(module=None, testLoader=unittest.defaultTestLoader)

graalpython/com.oracle.graal.python.test/src/tests/test_tagged_unittests.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
TAGS_DIR = "null"
5151

5252

53+
RUNNER = os.path.join(os.path.dirname(__file__), "run_cpython_test.py")
54+
55+
5356
def working_selectors(tagfile):
5457
if os.path.exists(tagfile):
5558
with open(tagfile) as f:
@@ -84,7 +87,7 @@ def fun(self):
8487
cmd.append("--inspect")
8588
if "-debug-java" in sys.argv:
8689
cmd.append("-debug-java")
87-
cmd += ["-S", "-m", "unittest"]
90+
cmd += ["-S", RUNNER]
8891
for testpattern in working_test[1]:
8992
cmd.extend(["-k", testpattern])
9093
testmod = working_test[0].rpartition(".")[2]
@@ -169,7 +172,7 @@ def parse_unittest_output(output):
169172
# (there will be one even if everything succeeds) filter out possible false-passes caused by
170173
# the tests catching all exceptions somewhere
171174
cmd += ['--experimental-options', '--python.CatchAllExceptions']
172-
cmd += ["-S", "-m", "unittest", "-v"]
175+
cmd += ["-S", RUNNER, "-v"]
173176
tagfile = os.path.join(TAGS_DIR, testfile_stem + ".txt")
174177
if retag and repeat == 0:
175178
test_selectors = []

0 commit comments

Comments
 (0)