Skip to content

Commit 63012df

Browse files
reyoungYang Yang(Tony)
authored andcommitted
Switch scope/program for every test (#10702)
1 parent 7e88026 commit 63012df

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

python/paddle/fluid/tests/unittests/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ function(py_test_modules TARGET_NAME)
2828
if(WITH_TESTING)
2929
set(options "")
3030
set(oneValueArgs "")
31-
set(multiValueArgs MODULES DEPS ARGS ENVS)
31+
set(multiValueArgs MODULES DEPS ENVS)
3232
cmake_parse_arguments(py_test_modules "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
3333
add_test(NAME ${TARGET_NAME}
3434
COMMAND env PYTHONPATH=${PADDLE_BINARY_DIR}/python ${py_test_modules_ENVS}
35-
${PYTHON_EXECUTABLE} -u -m unittest --verbose ${py_test_modules_MODULES} ${py_test_modules_ARGS}
35+
${PYTHON_EXECUTABLE} ${PADDLE_SOURCE_DIR}/tools/test_runner.py ${py_test_modules_MODULES}
3636
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
3737
endif()
3838
endfunction()

tools/test_runner.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import unittest
16+
import os
17+
import sys
18+
import paddle.fluid as fluid
19+
import importlib
20+
import cStringIO
21+
22+
23+
def main():
24+
sys.path.append(os.getcwd())
25+
some_test_failed = False
26+
for module_name in sys.argv[1:]:
27+
buffer = cStringIO.StringIO()
28+
main = fluid.Program()
29+
startup = fluid.Program()
30+
scope = fluid.core.Scope()
31+
with fluid.program_guard(main, startup):
32+
with fluid.scope_guard(scope):
33+
with fluid.unique_name.guard():
34+
test_loader = unittest.TestLoader()
35+
module = importlib.import_module(module_name)
36+
tests = test_loader.loadTestsFromModule(module)
37+
res = unittest.TextTestRunner(stream=buffer).run(tests)
38+
if not res.wasSuccessful():
39+
some_test_failed = True
40+
print >> sys.stderr, module_name, 'failed\n', buffer.getvalue(
41+
)
42+
43+
if some_test_failed:
44+
exit(1)
45+
46+
47+
if __name__ == '__main__':
48+
main()

0 commit comments

Comments
 (0)